[英]What's wrong with this pipe?
#include <unistd.h>
#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
int main (int argc, char * argv[])
{
int enteroParaElPipe;
int IDPROGRAMACLIENTE=getpid();
printf("%d",IDPROGRAMACLIENTE);
if((mkfifo("pipe",0666))==-1)
{
perror("error creating pipe, type 1");
exit(1);
}
if((enteroParaElPipe=open("pipe",O_WRONLY))==-1)
{
perror("error creating pipe, type 2");
exit(1);
}
char comando[200];
if(scanf("%199s", comando) == 1)
puts(comando);
int written;
escritos=write(enteroParaElPipe,"HOLA\n",5);
printf("Written: %d\n",written);
close(enteroParaElPipe);
return 0;
}
When trying to run this code I get: 尝试运行此代码时,我得到:
error creating pipe: Invalid argument
Why? 为什么?
(Modifications based on the first answers added) (根据添加的第一个答案进行修改)
Why are you passing getpid()
as the 2nd argument for mkfifo? 为什么要传递
getpid()
作为mkfifo的第二个参数?
The 2nd argument is the mode, as in, the FIFO file's permissions. 第二个参数是模式,例如FIFO文件的权限。 Type
man 3 mkfifo
for more information! 输入
man 3 mkfifo
以获取更多信息!
Cheers. 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.