Monitor Process Event with Timeout

2017-01-03 00:00:00 +0100

In case you have any questions or suggestions, you can leave comments
HERE . Thanks!

Generally speaking, the events in an operating system are either related to
file, signal, or process. For a file descriptor, the possible events could be
ready to read, write etc; for a signal, the events could be upon reception; for
a process, the events could be upon exit, upon calling exec or fork etc.

To monitor file related events with a timeout, there are system calls like
select, poll, etc. To monitor signal related events, there are two possible
solutions: the easier but non-standard one, use sigtimedwait; or use sigalfd
to create file descriptors related with a signal, and then apply select (this
could be used to monitor a child process when the signal is set as SIGCHILD).

But to monitor a process with a timeout? There come kqueue and kevent. In
fact, they are also able to do the file and signal monitor works, with proper
parameters fed to EV_SET macro. For detailed references, click
here.

In this post, a code snippet to monitor a process with time out is given (there
is not much code examples about process monitoring but a lot about network file
descriptors).