Search code examples
linuxsignalsexitsigchld

Linux: how to program to monitor process existing/quiting?


SIGCHLD can only be caught by father process to monitor if child process exits. But I wish to write a stand-alone program to monitor some processes, if they quit, report a log immediately.

Is there any programming ways that I can use, rather than using a shell "ps" command to monitor process name/id, and then query in a dead loop?


Solution

  • You can monitor process activity through proc pseudo-filesystem usually mounted at /proc. For reference use: https://www.kernel.org/doc/Documentation/filesystems/proc.txt