23,125
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(void){
char buffer[1024];
int num;
//if(mkfifo("pipe", 0666) == -1){
// perror("");
//}
int fd = open("pipe", O_WRONLY);
printf("open success\n");
while(1){
scanf("%s", buffer);
if(strcmp(buffer, "q") == 0){
break;
}
num = write(fd, buffer, strlen(buffer) + 1);
printf("Write char: %d\n", num);
}
close(fd);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(void){
char buffer[1024];
int fd = open("pipe", O_RDONLY);
printf("open success\n");
while(read(fd, buffer, 1024) > 0){
printf("-----------------------");
printf("%s", buffer);
}
printf("quit");
close(fd);
}