1

I need to monitor a process -- with a known PID -- and react to it either exiting for good, or writing into a file in a known subdirectory.

The file(s) may not initially exist. On BSD I would use kqueue specifying the different things I want to be woken up for. But this program is for Linux.

I know, inotify can advise me of new files created or existing files opened/closed in a directory. But it will not tell me about the process exiting...

How do I watch for all of these events? Ideally, this would be done in shell, but I could compile a helper C-program, which the shell-script would call...

Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
  • If the process exit()s, the file will be closed anyhow. /caseclosed – wildplasser Nov 07 '18 at 23:37
  • AFAIK there's no way to be notified of a process exiting (except for children of the current process, the parent receives a SIGCHLD signal). I think the only solution is periodically testing if the PID exists. – Barmar Nov 08 '18 at 00:46
  • 1
    I haven't tested it, but maybe adding watching for `/proc/NNNN` to be deleted, where `NNNN` is the process's pid, to your inotify events? – Shawn Nov 08 '18 at 05:06

0 Answers0