shell tricks and trapping signals

Paul Lussier p.lussier at comcast.net
Fri Nov 2 14:53:27 EDT 2007


"Ben Scott" <dragonhawk at gmail.com> writes:

>   I don't think children receive a signal when a parent process exits,
> and I cannot find anything about that documented in the signal(7) man
> page.  A parent process receives SIGCHLD when a child exits, but not
> the other way around.

I was thinking you could trap on $PPID == 1, but we found a different
work-around.  We now issue ssh with a -t option :) When the
controlling psuedo-tty exits, so does everything underneath it.

>Would a heartbeat mechanism be feasible?  In other words, have one
>process emit an "I'm still here" keep-alive periodically, and have
>the process at the other end of the SSH tunnel kill itself if it
>doesn't get a command within the timeout period.

I think a better way to do it would be to keep track of the PIDs
spawned from the controlling ssh process somehow, and rather than
having ssh process exit and leave them hanging, have it clean up then
exit.  This is exactly what using the psuedo-tty accomplishes.  But if
it didn't, it seems this is the easiest way to deal with the problem.
For the code we were dealing with, it would have required a lot more
hacking than just using 'ssh -t', which is why I was hoping to find
some way of trapping on the re-parenting of the spawned process.

-- 
Seeya,
Paul


More information about the gnhlug-discuss mailing list