开发者学堂课程【物联网开发- Linux 高级程序设计全套视频:读进程结束写进程再写命名管道写进程收到信号退出】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/660/detail/11039
读进程结束写进程再写命名管道写进程收到信号退出
通信过程中,读进程退出后,写进程的命名管道内写数据时,写进程也会(收到SIGPIPE信号)退出。
例:
04 fifo read4.c阻塞方式打开命名管道,验证读进程结束后,写进程再向管道写数据写进程会收到信号退出。
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[ ])
验证:
fd = open("./fifo",O _RDONLY);
If (td<0)
{
perror("open");
return 0,
}
printf("open read only sucess \n");
while(1 )
{
memset(buf,0,sizeof(buf) );
read(fd, buf,100);
printf("buf=%s\n”, buf);
sleep(1);
}
close(fd);
return 0;
}
运行结果如下:
读进程退出,再往里面 write 的时候,写进程会收到信号退出