I am trying to use a named pipe for communication within a process. Here is the code
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
void sigint(int num)
{
int fd = open("np", O_WRONLY);
write(fd, "y", 1);
close(fd);
}
main()
{
char ch[1];
int fd;
mkfifo("np", 0666);
signal(SIGINT, sigint);
fd = open("np", O_RDONLY);
read(fd, ch, 1);
close(fd);
printf("%c\n", ch[0]);
return;
}
I want the main unit to lock until something is written to the handset. The problem is that after opening the pipe, it blocks the sigint () signal. Is it assumed that the pipe is already open for reading earlier in main ()?
source
share