Question

The mkfifo function takes 2 arguments, path and mode. But I don't know what is the format of the path that it uses. I am writing a small program to create a named pipe and as path in the mkfifo. Using /home/username/Documents for example, but it always returns -1 with the message Error creating the named pipe.: File exists.

I have checked this dir a lot of times and there is no pipe inside it. So I am wondering what is the problem. The mode I use in mkfifo is either 0666 or 0777.

Was it helpful?

Solution

You gave mkfifo() the name of an existing directory, thus the error. You must give it the name of a non-existing file, e.g.

mkfifo("/home/username/Documents/myfifo", 0600);

OTHER TIPS

The 'path' argument to mkfifo() has to specify a full path, the directory and the filename that is.

Thus, it would be:

char *myfifo="/home/username/Documents/mypipe";

mkfifo(myfifo, 0777);

As a side note, you should avoid using octal permission bits and use named constants instead (from sys/stat.h), so:

mkfifo(myfifo, S_IRWXU | S_IRWXG | S_IRWXO);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top