mkfifo?
两个小程序,注释部分和原来的语句有什么不同,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;
}