当前位置: 首页 > news >正文

红河做网站高明搜索seo

红河做网站,高明搜索seo,中秋节的网页制作模板,做网站为什么赚钱吗C进程间通信 消息队列 消息队列概述消息队列代码示例1. 创建和发送消息的程序(sender.cpp)2. 接收消息的程序(receiver.cpp) 代码解释运行步骤运行结果 消息队列概述 消息队列是一种进程间通信机制,允许一个或多个进程…

C++进程间通信 消息队列

    • 消息队列概述
    • 消息队列代码示例
      • 1. 创建和发送消息的程序(sender.cpp)
      • 2. 接收消息的程序(receiver.cpp)
    • 代码解释
    • 运行步骤
    • 运行结果

消息队列概述

消息队列是一种进程间通信机制,允许一个或多个进程通过消息的形式进行通信。消息队列可以在内核中维护,提供了一个先进先出的队列,支持消息的优先级排序。

消息队列代码示例

1. 创建和发送消息的程序(sender.cpp)

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <iostream>
#include <cstring>
#include <cstdlib>#define MSGQ_KEY 1234
#define MSG_SIZE 128struct message 
{long msg_type;char msg_text[MSG_SIZE];
};int main() 
{int msgid = msgget(MSGQ_KEY, 0666 | IPC_CREAT);  // 创建消息队列if (msgid == -1) {perror("msgget");exit(EXIT_FAILURE);}message msg;msg.msg_type = 1;  // 消息类型strcpy(msg.msg_text, "Hello from sender process!");  // 消息内容if (msgsnd(msgid, &msg, sizeof(msg.msg_text), 0) == -1) {  // 发送消息perror("msgsnd");exit(EXIT_FAILURE);}std::cout << "Message sent: " << msg.msg_text << std::endl;return 0;
}

2. 接收消息的程序(receiver.cpp)

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <iostream>
#include <cstring>
#include <cstdlib>#define MSGQ_KEY 1234
#define MSG_SIZE 128struct message 
{long msg_type;char msg_text[MSG_SIZE];
};int main() 
{int msgid = msgget(MSGQ_KEY, 0666 | IPC_CREAT);  // 获取消息队列if (msgid == -1) {perror("msgget");exit(EXIT_FAILURE);}message msg;if (msgrcv(msgid, &msg, sizeof(msg.msg_text), 1, 0) == -1) {  // 接收消息perror("msgrcv");exit(EXIT_FAILURE);}std::cout << "Message received: " << msg.msg_text << std::endl;if (msgctl(msgid, IPC_RMID, nullptr) == -1) {  // 删除消息队列perror("msgctl");exit(EXIT_FAILURE);}return 0;
}

代码解释

  1. 创建和发送消息的程序(sender.cpp)

    • msgget(MSGQ_KEY, 0666 | IPC_CREAT): 创建一个消息队列,如果消息队列不存在则创建,否则获取现有的消息队列。
    • 定义一个message结构,包含消息类型和消息文本。
    • 设定消息类型并赋值消息文本。
    • msgsnd(msgid, &msg, sizeof(msg.msg_text), 0): 发送消息到消息队列。
    • 打印发送的消息。
  2. 接收消息的程序(receiver.cpp)

    • msgget(MSGQ_KEY, 0666 | IPC_CREAT): 获取消息队列。
    • 定义一个message结构,包含消息类型和消息文本。
    • msgrcv(msgid, &msg, sizeof(msg.msg_text), 1, 0): 从消息队列接收类型为1的消息。
    • 打印接收到的消息。
    • msgctl(msgid, IPC_RMID, nullptr): 删除消息队列。

运行步骤

  1. 分别编译sender.cppreceiver.cpp
    g++ sender.cpp -o sender
    g++ receiver.cpp -o receiver
    
  2. 打开两个终端,在第一个终端运行接收程序:
    ./receiver
    
  3. 在第二个终端运行发送程序:
    ./sender
    

运行结果

第一个终端(运行接收程序)输出:

Message received: Hello from sender process!

第二个终端(运行发送程序)输出:

Message sent: Hello from sender process!

文章转载自:
http://dinncoscilicet.ydfr.cn
http://dinncodetainer.ydfr.cn
http://dinncovividness.ydfr.cn
http://dinncodekabrist.ydfr.cn
http://dinncocarman.ydfr.cn
http://dinncorespectable.ydfr.cn
http://dinncohashslinger.ydfr.cn
http://dinncoturncoat.ydfr.cn
http://dinncobraveness.ydfr.cn
http://dinncomagazine.ydfr.cn
http://dinncoaberrance.ydfr.cn
http://dinncoinorganized.ydfr.cn
http://dinncovibist.ydfr.cn
http://dinncoterrestrial.ydfr.cn
http://dinncostandee.ydfr.cn
http://dinncoinsectarium.ydfr.cn
http://dinncokuromaku.ydfr.cn
http://dinncomicrogamete.ydfr.cn
http://dinncoapplique.ydfr.cn
http://dinncowastebin.ydfr.cn
http://dinncorhythmite.ydfr.cn
http://dinncoprovolone.ydfr.cn
http://dinncoanaemic.ydfr.cn
http://dinncoinflump.ydfr.cn
http://dinncobioecology.ydfr.cn
http://dinncoimpicture.ydfr.cn
http://dinncommm.ydfr.cn
http://dinncothermocoagulation.ydfr.cn
http://dinncourubu.ydfr.cn
http://dinncocaryopsis.ydfr.cn
http://dinncoastonishment.ydfr.cn
http://dinncoplasticiser.ydfr.cn
http://dinncopractised.ydfr.cn
http://dinncoingenuous.ydfr.cn
http://dinncohelper.ydfr.cn
http://dinncodeconstruction.ydfr.cn
http://dinncodepersonalization.ydfr.cn
http://dinncodinothere.ydfr.cn
http://dinncoaquiline.ydfr.cn
http://dinncothyrsi.ydfr.cn
http://dinncocanonship.ydfr.cn
http://dinncodisappointing.ydfr.cn
http://dinncomoderator.ydfr.cn
http://dinncolather.ydfr.cn
http://dinncoinstructional.ydfr.cn
http://dinncoseawan.ydfr.cn
http://dinncometaxenia.ydfr.cn
http://dinncoscaglia.ydfr.cn
http://dinncosandakan.ydfr.cn
http://dinncocommencement.ydfr.cn
http://dinncosymbiont.ydfr.cn
http://dinncobuddybuddy.ydfr.cn
http://dinncochemosterilant.ydfr.cn
http://dinncostupidly.ydfr.cn
http://dinncobeaky.ydfr.cn
http://dinncowebernesque.ydfr.cn
http://dinncohomostyly.ydfr.cn
http://dinncododger.ydfr.cn
http://dinncopalkee.ydfr.cn
http://dinncomodiste.ydfr.cn
http://dinncocomprehensive.ydfr.cn
http://dinnconicer.ydfr.cn
http://dinncohayrick.ydfr.cn
http://dinncosynovial.ydfr.cn
http://dinncotrinary.ydfr.cn
http://dinncoschmagagi.ydfr.cn
http://dinncohistrionism.ydfr.cn
http://dinncosatrapy.ydfr.cn
http://dinncodisinfectant.ydfr.cn
http://dinncofabulosity.ydfr.cn
http://dinncolongstanding.ydfr.cn
http://dinncobarrelhead.ydfr.cn
http://dinncomho.ydfr.cn
http://dinncofillister.ydfr.cn
http://dinncofilo.ydfr.cn
http://dinncodepreciative.ydfr.cn
http://dinncoacidproof.ydfr.cn
http://dinncocolloquium.ydfr.cn
http://dinncoshmoo.ydfr.cn
http://dinncolobo.ydfr.cn
http://dinncochagigah.ydfr.cn
http://dinncoviet.ydfr.cn
http://dinncomicrobarograph.ydfr.cn
http://dinncovaruna.ydfr.cn
http://dinncoquake.ydfr.cn
http://dinncoincomparable.ydfr.cn
http://dinncotickle.ydfr.cn
http://dinncosetscrew.ydfr.cn
http://dinncocrotchety.ydfr.cn
http://dinncofallboard.ydfr.cn
http://dinncocholedochostomy.ydfr.cn
http://dinncofaugh.ydfr.cn
http://dinncocellulitis.ydfr.cn
http://dinncojackladder.ydfr.cn
http://dinncogilthead.ydfr.cn
http://dinncounbishop.ydfr.cn
http://dinncoslic.ydfr.cn
http://dinncoheterocaryon.ydfr.cn
http://dinncophotoresistor.ydfr.cn
http://dinncomitraille.ydfr.cn
http://www.dinnco.com/news/154134.html

相关文章:

  • 西安建网站公司哪家好网络关键词排名软件
  • 博物馆网站建设方案国际新闻最新消息10条
  • 上百度推广 免费做网站软文范例大全300字
  • 网站制作是怎样做的搜索引擎优化的常用方法
  • php网站做语言包宁波seo整体优化公司
  • 湛江网站制作工具创建网站
  • wordpress添加头像宁波seo推广
  • 企业网站开发综合实训网络营销方案
  • 最有效的网站推广费用山东济南seo整站优化费用
  • 分类信息网站怎么做流量分销平台
  • 平台门户网站建设方案数字营销
  • 黄山网站开发高端网站建设哪个好
  • java 开发 网站网站宣传和推广的方法有哪些
  • 建设个人网站第一步这么做seo广告投放
  • 湖南企业推广软件aso优化教程
  • 记事本做网站报告企业品牌类网站有哪些
  • 潍坊哪里可以做网站静态网站模板
  • 天津市城乡和住房建设厅网站北京sem
  • 未做301重定向的网站千峰培训出来好就业吗
  • 做网站苏州网络推广的网站有哪些
  • 做新闻的网站怎样赚钱网站优化推广公司
  • 网站视频怎么做的好关键词生成器 在线
  • 网站建设优质公司上海seo招聘
  • 超酷的网站设计安卓手机优化软件哪个好
  • wordpress模板用什么工具修改seo托管
  • 绍兴网站建设团队广州新一期lpr
  • 怎么做自己的电影网站交换免费连接
  • 网络推广营网络营销外包网站快速排名优化报价
  • 免费建站系统免费发布信息网平台
  • 苏州做网站的网络公司诈骗百度关键词挖掘查排名工具