EmbLogic's Blog

Changing the behavior of Pipe using funtion- ‘fcntl()’

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 :-P

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>