Catching SIG of running process with bash

Hello all!

I'm writing a script that will catch when an outside process crashes (SIGHUP, right?) without having to loop into infinity.
With that in mind, I came across the trap utility and thought if could be used to monitor another process other than it's own. But from what I've read, I'm thinking it might be more limited than what I initially believed.

Could someone point me in the right direction? :slight_smile:

This is what I have on trap so far:
Traps
trap(1) - Linux man page

Suggested direction: man ps; man fork # Possibly for might return no results - use google then
Suggested improvement: man sh; man ksh; man bash

Extra description:
SIGHUP = SIGnal HangUP. AFAIK it was used in the past when you connected using a modem and then disconnected (hanged up). Now its meaning might be different - check the kernel source (signals.h if I remembered it right).

"trap" might be used to trap almost all the signals (except -9 obviously). The only thing is that it traps your own process - not other processes.

Why would anyone monitor other processes? Some OSes might restrict you so that you wouldn't see processes of other users. Then I assume that you might want to monitor own processes. In such case - check when you are running a new process and store the PID of started process. You might read about PIDs and about pseudo-variables like $!,$$,$PPID. In addition use $?.

You might be unlucky and someone might have created a very nasty code - a code-mine. I am describing code which starts, runs some other process in the background, disowns it forgetting about its PID and then exits (probably without specific return code since such code is usually a crap).