Reputation: 23
In this code my program crashes in when I am opening the pipe for writing.
char pipe[30];
int fd, tmp = 2;
sprintf(pipe, "root_%d", getpid());
ret_val = mkfifo(pipe, 0666);
fd = open(pipe, O_WRONLY); //HERE IS CRASHING - SUDDENLY FREEZES
write(fd, &tmp, sizeof(int));
close(fd)
All seems good, but where is my mistake;
Upvotes: -1
Views: 300
Reputation: 7923
It is an expected behavior. From man 7 fifo
:
Normally, opening the FIFO blocks until the other end is opened also.
So your open
does not return until somebody opens the same pipe for reading. You may want to add O_NONBLOCK
flag (and likely get SIGPIPE
on writing), or revisit the design.
Upvotes: 1