mkfifo?

machaoqun6666 2008-09-19 11:44:21
两个小程序,注释部分和原来的语句有什么不同,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;
}
...全文
121 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
bshawk 2008-09-19
  • 打赏
  • 举报
回复
你最好判断下用注释部分的时候,你的每一步是否成功?
mkfifo是否成功?
open是否成功?
write是否成功?

然后才能确定问题所在!

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧