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

电子商务网站网站建设媒介星软文平台

电子商务网站网站建设,媒介星软文平台,做水电到哪个网站找信息,网站结合微信进程间通信机制(IPC) 简述 IPC:Inter Process Communication 进程和进程之间的用户空间相互独立,但是4G内核空间共享,进程间的通信就是通过这4G的内核空间 分类 传统的进程间通信机制 无名管道(pipe) 有名管道&…

进程间通信机制(IPC)

简述

IPC:Inter Process Communication

进程和进程之间的用户空间相互独立,但是4G内核空间共享,进程间的通信就是通过这4G的内核空间

分类

传统的进程间通信机制

无名管道(pipe)

有名管道(fifo)

信号(signal)

System V中的IPC对象和IPC的区别

消息队列(message queue)

共享内存(shared memory)

信号灯集(semaphore)

可用于主机传输的通信机制

套接字(socket)

消息队列

概念

在内核内存中创建一个队列,进程需要将数据打包成结点,添加到队尾中,或者从队列中读取结点,可以通过消息类型进行消息分类

特点

需要打包,有特定的格式以及消息类型

按照先进先出原则,但是也可以限制消息类型读取

独立于进程,灯进程结束后,消息队列以及其中的内容不会删除,除非中期操作系统或者手动删除

在Linux系统下,可以通过命令ipcs查看消息队列,通过ipcrm -q msqid删除消息队列

函数

ftok()函数,获得一个Key值用来创建消息队列,通过相同的key值可以访问对应的消息队列

msgget()函数创建一个消息队列获得起id号

msgsnd()发送消息到指定消息队列

msgrcv()获取对应消息队列中对应的消息

msgctl()控制消息队列,常用于删除消息队列

#include<myhead.h>
#include<sys/msg.h>
#include<sys/ipc.h>
struct msgbuf
{long mtype;      //消息类型char mtext[128]; //消息内容
};//线程1函数
void *task1(void *arg)
{int msqid = *(int *)arg;//获取消息队列id号struct msgbuf msbuf;//声明消息结构体printf("A:\n\t");fflush(stdout);while (1){msbuf.mtype = 1;//消息类型fgets(msbuf.mtext,sizeof(msbuf.mtext),stdin);msbuf.mtext[strlen(msbuf.mtext)-1]='\0';if(msgsnd(msqid,&msbuf,sizeof(msbuf)-sizeof(long),0) == -1){perror("msgsnd");return NULL;}//printf("线程%d:发送成功\n",getpid());printf("A:\n\t");fflush(stdout);if (!strcmp(msbuf.mtext,"quit")){system("clear");exit(0);}}pthread_exit(NULL);
}//线程2函数
void *task2(void *arg)
{int msqid = *(int *)arg;struct msgbuf buf;ssize_t num = 0;while (1){bzero(&buf,sizeof(buf));if ((num = msgrcv(msqid,&buf,sizeof(buf.mtext),2,0))<0){//perror("msgrcv");return NULL;}printf("\nB:\n\t%s\n",buf.mtext);printf("A:\n\t");fflush(stdout);if (!strcmp(buf.mtext,"quit")){msgctl(msqid,IPC_RMID,NULL);system("clear");exit(0);}}pthread_exit(NULL);
}
int main(int argc, const char *argv[])
{key_t key = ftok("./",0);if (key == -1){perror("ftok");return -1;/* code */}umask(0);int msqid = msgget(key,IPC_CREAT|0664);if (msqid == -1){perror("msgget");return -1;}pthread_t tid1,tid2;if (pthread_create(&tid1,NULL,task1,&msqid) != 0){printf("线程1创建失败\n");}if (pthread_create(&tid2,NULL,task2,&msqid) != 0){printf("线程1创建失败\n");}pthread_join(tid1,NULL);pthread_join(tid2,NULL);return 0;
}
#include<myhead.h>
//#include<sys/msg.h>
//#include<sys/ipc.h>
struct msgbuf
{long mtype;      //消息类型char mtext[128]; //消息内容
};//线程1函数
void *task1(void *arg)
{int msqid = *(int *)arg;struct msgbuf msbuf;printf("B:\n\t");fflush(stdout);while (1){msbuf.mtype = 2;fgets(msbuf.mtext,sizeof(msbuf.mtext),stdin);msbuf.mtext[strlen(msbuf.mtext)-1]='\0';if(msgsnd(msqid,&msbuf,sizeof(msbuf)-sizeof(long),0) == -1){perror("msgsnd");return NULL;}//printf("线程%d:发送成功\n",getpid());printf("B:\n\t");fflush(stdout);if (!strcmp(msbuf.mtext,"quit")){system("clear");exit(0);}}pthread_exit(NULL);
}//线程2函数
void *task2(void *arg)
{int msqid = *(int *)arg;struct msgbuf buf;ssize_t num = 0;while (1){bzero(&buf,sizeof(buf));if ((num = msgrcv(msqid,&buf,sizeof(buf.mtext),1,0))<0){//perror("msgrcv");return NULL;}printf("\nA:\n\t%s\n",buf.mtext);printf("B:\n\t");fflush(stdout);if (!strcmp(buf.mtext,"quit")){msgctl(msqid,IPC_RMID,NULL);system("clear");exit(0);}}pthread_exit(NULL);
}
int main(int argc, const char *argv[])
{key_t key = ftok("./",0);if (key == -1){perror("ftok");return -1;/* code */}umask(0);int msqid = msgget(key,IPC_CREAT|0664);if (msqid == -1){perror("msgget");return -1;}pthread_t tid1,tid2;if (pthread_create(&tid1,NULL,task1,&msqid) != 0){printf("线程1创建失败\n");}if (pthread_create(&tid2,NULL,task2,&msqid) != 0){printf("线程1创建失败\n");}pthread_join(tid1,NULL);pthread_join(tid2,NULL);return 0;
}

http://www.hkea.cn/news/293429/

相关文章:

  • 做木皮的网站裂变营销五种模式十六种方法
  • 精美 企业网站模板微信软文推广怎么做
  • 怎么建立一个网站里面可以查询资料百度权重域名
  • 网站建设顺序镇江交叉口优化
  • 低价企业网站搭建软文新闻发布网站
  • 创造与魔法官方网站做自己喜欢的事seo视频
  • 淘宝联盟推广网站怎么做吉安seo招聘
  • 工程招聘网站如何免费制作自己的网站
  • 网站建设调研问卷搜易网托管模式的特点
  • 在哪个网站可以做java面试题宁德市蕉城区疫情
  • 2021年重大新闻事件seo快速工具
  • 拼多多网店南宁优化推广服务
  • 洛阳建筑公司排名长沙官网seo服务
  • 网站关键词优化公司哪家好企业网站seo点击软件
  • 做网站有必要?优化师培训
  • 网站怎么发布信息百度推广优化技巧
  • 西安软件培训百度百科优化排名
  • 网站上文章加入音乐是怎么做的网页代码
  • 深圳公布最新出行政策徐州seo招聘
  • wordpress的漏洞seo优化知识
  • 网站建设高端seo和sem分别是什么
  • 成交功能网站怎么推广自己的产品
  • 北京宣传片网站seo综合查询
  • 滨海网站建设公司百度指数的使用
  • 湛江网站建设外包seo到底是什么
  • 做收集信息的网站河源市企业网站seo价格
  • 有赞短链接生成汕头seo推广
  • 团队做网站分工搜索引擎案例分析结论
  • 企业网站的建设过程做整站优化
  • 最简单的cms网站怎么做惠州抖音seo