📄 data_deal.c
字号:
#include "outshm.h"
int main(void)
{
struct exchange *shm;
int producer, consumer, i;
//creat and init consumer
consumer = open_semaphore_set(ftok("consumer",0),1);
init_a_semaphore(consumer,0,1);
//creat and init producer
producer = open_semaphore_set(ftok("producer",0),1);
init_a_semaphore(producer,0,1);
//get and connect the shm named"shared"
shm = (struct exchange *)shminit(ftok("shared",0));
//read data from the shm written by the assistant process,output it
for(i=0; ; i++)
{
semaphore_V(consumer);
semaphore_P(producer);
//deal with the data,end loop with "end"
printf("data received:%s,sequence:%d\n",shm->buf,shm->seq);
if (strcmp(shm->buf,"end",3) == 0)
break;
}
rm_semaphore(producer);
rm_semaphore(consumer);
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -