23,121
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
mkfifo("/mnt/hgfs/cocat/danei/uc3/a.fifo", 0600);
int fd = open("/mnt/hgfs/cocat/danei/uc3/a.fifo", O_WRONLY);
if (fd < 0)
{
perror("open");
return -1;
}
printf("pipe ready!\n");
do
{
printf("input text:");
char str[100];
fgets(str, 100, stdin);
write(fd, str, sizeof(str));
if (strcmp(str, "bye") == 0)
{
break;
}
}
while (1);
close(fd);
return 0;
}