0

I'm trying to create a named pipe in C, but have not had any success.

Here is my code:

#define FIFO_NAME "/tmp/myfifo"
int main(){
    int fd;
    fd = mkfifo(FIFO_NAME, 0666);//, 0);
    if(fd<0){
      fprintf(stderr,"Error creating fifo\n");
      exit(0);
    }

On running the above code every time output comes out:

Error creating fifo

Please help.

vidit jain
  • 493
  • 1
  • 5
  • 13

2 Answers2

0

You want to replace fprintf(stderr,"Error creating fifo\n"); by perror("mkfifo() failed");. This gives you the long text error message which corresponds to the value of errno set by mkfifo() on failure. – alk

Thanks that worked, it had a existing file by same name. – vidit jain

Armali
  • 18,255
  • 14
  • 57
  • 171
0

Execute the program in a Unix environment. Even the folder directory should be in the Unix environment. Also include #include<unistd.h> in your code. However #include<unistd.h> and mkfifo only work in Unix environment. So execute the program in a Unix terminal. I had this problem and that's how I solved it.