Reputation: 22270
#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)
Upvotes: 0
Views: 636
Reputation: 13983
The second argument to mkfifo is a mode_t representing the permissions on the fifo.
Try: mkfifo("pipe", 0666);
Upvotes: 1
Reputation: 77089
Why are you passing getpid()
as the 2nd argument for mkfifo?
The 2nd argument is the mode, as in, the FIFO file's permissions. Type man 3 mkfifo
for more information!
Cheers.
Upvotes: 2