mkfifo?

machaoqun6666 machaoqun6666 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
两个小程序,注释部分和原来的语句有什么不同,mkfifo第一个参数有要求吗?为什么用注释的就不能把字符串传过去?
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main()
{
int fd;
char str[12]="hello world";
mkfifo("fifoa",O_CREAT|O_EXCL); //mkfifo("fifo",O_CREAT|O_EXCL);
fd=open("fifoa",O_WRONLY); //fd=open("fifo",O_WRONLY);
write(fd,str,12);
sleep(1);
close(fd);
return 0;
}
******************************************
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int main()
{
int fd;
char str[12];
fd=open("fifoa",O_RDONLY); //fd=open("fifo",O_RDONLY);
memset(str,0,sizeof(str));
read(fd,str,12);
write(STDOUT_FILENO,str,12);
close(fd);
return 0;
}
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
machaoqun6666
Linux/Unix社区 23,224 成员 74,535 内容