warwcat warwcat - 6 months ago 33
Linux Question

Don't enter on if and don't pass through

I have an if statement:

printf("name");
if((fp = fopen(path, "r")) == NULL) {
perror("fopen");
exit(1);
}
printf("name2");//Debug propose
while(fgets(mensagem,250,fp)!=NULL){
printf("%s",mensagem);
}

fclose(fp);


For some reason ,
name2
is never printed but
name
is printed ,
path
is a Fifo:

mknod(path, S_IFIFO|0666, 0);

Answer

From the FIFO man page (http://man7.org/linux/man-pages/man7/fifo.7.html):

Normally, opening the FIFO blocks until the other end is opened also.

That is, unless you open it explicitly in nonblocking mode.

So, I would expect your process to be hanging in the fopen() call until someone opens the fifo for writing as well.

Comments