Pause, please

The pause is a very good example of a blocking call; when a process calls this API, it blocks, that is, it goes to sleep waiting for an event; the event: the arrival of any signal to it. The moment a signal arrives, the pause is unblocked and execution continues. Of course, delivery of a fatal signal will cause the unsuspecting process to die:

include <unistd.h>
int pause(void);

Throughout, we have said that checking system calls for their failure case -1 is considered very important: a best practice to always follow. The pause(2) throws up an interesting exception case: it seems to be the one system call that always returns -1 and errno is set to the value EINTR Interrupted system call (the interruption being the signal of course).

For this reason, we often code the pause as follows:

(void)pause();

The typecast to void is to inform tools such as the compiler and static analyzers that we don't really care about the return value from pause.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset