第一关有问题
第二关
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#include <string.h>
void namepipe_commu(const char *buffer)
{
/***********begin***********/
int fd;
int w_num;
if((mkfifo("./my_fifo",0777)<0))
{
printf("cannot create fifo...\n");
exit(1);
}
//以阻塞型只写方式打开fifo
fd=open("./my_fifo",O_WRONLY);
w_num=write(fd,buffer,strlen(buffer));
/***********end***********/
}
第三关
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
struct msgbuf
{
long mytype;
char bookname[100];
};
void mq_commu (void)
{
/*********Begin*********/
//创建消息队列
int msgid = msgget((key_t)0x1234, 0666 | IPC_CREAT);
struct msgbuf data[4];
int i;
for(i=0;i<4;i++){
data[i].mytype=66;
}
strcpy(data[0].bookname, "C");
strcpy(data[1].bookname, "Linux");
strcpy(data[2].bookname, "Makefile");
strcpy(data[3].bookname, "End");
for(i=0;i<4;i++){
msgsnd(msgid, &data[i], sizeof(struct msgbuf)-sizeof(long), 0);
if(strcmp(data[i].bookname,"End")==0){
break;
}
sleep(1);
}
/**********End**********/
}