Why Does My Program Hang When Opening a Mkfifo-Ed Pipe

C++ program is hanging when invoking 'mkfifo' (Lustre FS)

I got an answer from the author https://github.com/alexdobin/STAR/issues/687

The program generated a shell script that was missing a shebang delcaration: this prevented the fifo stream from working.

mkfifo() error --- Error creating the named pipe.: File exists

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);

How do I perform a non-blocking fopen on a named pipe (mkfifo)?

You could open() your pipe O_RDONLY | O_NONBLOCK, and if you want the C stream, you can get it with fdopen(). However, there might be a problem with the select() - AFAIK, a pipe fd open for reading that has no writer is always prepared for reading, and read() returns 0, so the select() would fire indefinitely.

A kludgy way of overcoming this would be to open the pipe O_RDWR; that is, have at least one writer (your C++ program). Which would solve your problem anyway.



Related Topics



Leave a reply



Submit