返回信息流问一下这个代码为什么到注释那里就停了
代码在linux下可以运行 是关于 FIFO的
#include "unistd.h"
#include "stdio.h"
#include "string.h"
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdarg.h>
#include <syslog.h>
const unsigned int FILE_MODE=(S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
const char FIFO1[]="/tmp/fifo.1";
const char FIFO2[]="/tmp/fifo.2";
int main()
{
int readfd,writefd;
if((mkfifo(FIFO1,FILE_MODE)<0)&&errno!=EEXIST)
{
//错误处理 无视
char buff[100];
snprintf(buff,sizeof(buff),"can't creat %s",FIFO1);
perror(buff);
}
if((mkfifo(FIFO2,FILE_MODE)<0)&&errno!=EEXIST)
{
//错误处理 无视
unlink(FIFO1);
char buff[100];
snprintf(buff,sizeof(buff),"can't creat %s",FIFO2);
perror(buff);
}
printf("1\n");//到这里就停了
readfd=open(FIFO1,O_RDONLY,0);
writefd=open(FIFO2,O_WRONLY,0);
exit(0);
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #46180同步于 2010/11/12
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
程序莫名其妙就死了
lockhart
2010/11/12镜像同步8 回复
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
【 在 ki 的大作中提到: 】
: 阻塞?
下面这个呢?只写
const unsigned int FILE_MODE=(S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
const char FIFO1[]="/tmp/fifo.1";
const char FIFO2[]="/tmp/fifo.2";
const int MAXLINE=80;
int main()
{
int readfd,writefd;
pid_t childpid;
if((mkfifo(FIFO1,FILE_MODE)<0)&&errno!=EEXIST)
{
char buff[100];
snprintf(buff,sizeof(buff),"can't creat %s",FIFO1);
perror(buff);
}
printf("server begin!\n");
writefd=open(FIFO1,O_WRONLY,0);
printf("server end!\n");
exit(0);
}
【 在 zxsword 的大作中提到: 】
: 就是阻塞呗。。。
: 把UNP卷2的那一章看完,就懂了
明白了 这样写只能两个进程操作一个fifo 不然一直阻塞