有名管道
写程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
int f;
int fd;
// char buff[10];
f = mkfifo("myfifo",06666);//创建有名管道
char buf[] = "abcd";
fd = open("myfifo",O_WRONLY);//以只写权限打开
// fd = open("myfifo",O_RDWR);
write(fd,buf,strlen(buf));//对管道进行写操作,strlen(buf),写了个5读的时候会出现断错误!
// read(fd,buff,5);
// printf("%s", buff);
return 0;
}
读程序
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
int fd;
char buf[10];
bzero(buf, 10);
printf("fuck\n");
fd = open("myfifo",O_RDONLY);//打开已经创建好的管道
printf("test %d\n",fd);
read(fd,buf,4);//读管道
printf("buf: %s\n", buf);
return 0;
}