#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
int main(void) {
printf("%d进程:创建管道...\n", getpid());
if (mkfifo("myfifo", 0666) == -1) {
perror("mkfifo");
return -1;
}
printf("%d进程:打开管道...\n", getpid());
int fd = open("myfifo", O_WRONLY);
if (fd == -1) {
perror("open");
return -1;
}
printf("%d进程:发送数据...\n", getpid());
char buf[1024];
for (;;) {
printf("> ");
fgets(buf, sizeof(buf) / sizeof(buf[0]), stdin);
if (!strcmp(buf, "!\n"))
break;
if (write(fd, buf, strlen(buf) * sizeof(buf[0])) == -1) {
perror("write");
return -1;
}
}
printf("%d进程:关闭管道...\n", getpid());
if (close(fd) == -1) {
perror("close");
return -1;
}
printf("%d进程:删除管道...\n", getpid());
if (unlink("myfifo") == -1) {
perror("unlink");
return -1;
}
printf("%d进程:完成任务!\n", getpid());
return 0;
}
这个代码是不是输入!和回车跳出循环,但是现在一直卡在输入界面