The pipe() system call is used to create a pipe which returns two file-descriptors; one for read and one for write. If pipe is empty, then reader waits until data is available to read from the pipe which is termed as Block-On-Read.
But we can change this behaviour by using fcntl() funtion as follows;
fcntl(rfd, F_SETFL, O_NONBLOCK);
Here,
rfd =Read File Descriptor given by pipe() call,
F_SETFL = It tells fcntl() what to do with rfd,
O_NONBLOCK = Set the read flags associated with rfd so as to perfrom Non-Block Read.
Here’s also another way which is ‘pipe2()’ system call. Which quite easy