Blocking System call
A blocking system call is a system call that blocks the process execution until the requested operation is completed. The blocking system call can be used in synchronous I/O or asynchronous I/O.
Synchronous (blocking) input and output methods: read(), write() Asynchronous input and output methods: select(), poll()
The following example shows how to use the read() system call. The read() function returns the number of bytes actually read, which may be less than the number of bytes requested. The difference between the two is not always returned as an error condition.
The following example shows how to use the write() system call. The write() function writes up to count bytes from the buffer pointed to by buf to file descriptor fd.
It returns the number of bytes written, which may be less than the count if a write error occurs. The following example shows how to use the select() system call. The select() function blocks until input or output become possible for any of a set of open files. The descriptors will be updated with information about whether I/O is possible for them or not.
The following example shows how to use poll() system call. The poll() function returns the number of file descriptors that are ready for reading (0) and writing (1), respectively. It returns -1 on failure with errno set appropriately.
Blocking and Nonblocking IO in Operating System
Blocking and non-blocking IO are two different methods used by OS to handle I/O operations. A blocking call is where the OS decides that it needs to wait for a certain operation to complete before allowing the program to continue execution. The result of this is that user can’t do anything else while waiting on a system call; if your program doesn’t have any other activity, then it should be able to wait indefinitely without causing any problems. On the other hand, non-blocking calls (also known as asynchronous operations) don’t block the thread until they finish their work; instead, this type of system call returns immediately after completing its job without having any effect on what’s happening in other threads.
Contact Us