Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the write() function in C blocking or non-blocking?

Tags:

c

linux

posix

I looked on the Linux man pages for the answer but can't seem to find it. I know that read() is blocking but I'm still not sure about write(). Can anyone point me to any documentation for clarification?

like image 609
JJTO Avatar asked Feb 24 '17 23:02

JJTO


People also ask

Is write system call blocking?

No, it only blocks the process until the content of the buffer is copied to kernel space.

Is read () a blocking call?

Note: The default mode is blocking. If data is not available to the socket, and the socket is in blocking and synchronous modes, the READ call blocks the caller until data arrives.

What is the function of write ()?

The write() method writes a specified text to the file. Where the specified text will be inserted depends on the file mode and stream position. "a" : The text will be inserted at the current file stream position, default at the end of the file.

What is non-blocking write?

Non-blocking writes eliminate such blocking by buffering the written data elsewhere in memory and unblocking the writing process immediately. Subsequent reads to the updated page locations are also made non-blocking.


1 Answers

Read POSIX on read() and write(). See also functions such as open() and pipe().

It depends on the attributes of the file descriptor you're reading from or writing to (think O_NONBLOCK, for example), and on the underlying file type (disk file vs pipe vs FIFO vs socket vs character or block special), and so on.

Succinctly, both read() and write() can be blocking or non-blocking, depending on circumstances.

like image 179
Jonathan Leffler Avatar answered Nov 24 '22 02:11

Jonathan Leffler