|Just another Perl shrine|
Unwanted SSH child survives after ssh sessionby cmv (Chaplain)
|on Aug 11, 2009 at 20:03 UTC||Need Help??|
cmv has asked for the
wisdom of the Perl Monks concerning the following question:
Running the following ssh command locally:
ssh user@host tail -f /etc/passwd
Results in the following 2 processes on the far end machine (note PGID & SID):
As expected, when I ctrl-c out of the ssh command on the originating local computer, I loose the sshd_config process at the far end, but the tail -f child process survives and looks like this:
I would like for the child process to die when I ctrl-c out of the ssh command. How can I do this?
Put another way, how can I get the child process (tail -f) to be in the same process group as the parent (sshd_config)?
My first thought was to use perl's setpgrp command: setpgrp(PID, PGRP) where:
However, this seems to always fail on SunOS. Probably because of what is described in the setpgrp camel book description:
Sets the current process group for the specified PID, 0 for the current process. Will produce a fatal error if used on a machine that doesn't implement POSIX setpgid(2) or BSD setpgrp(2). If the arguments are omitted, it defaults to 0,0 . Note that the BSD 4.2 version of setpgrp does not accept any arguments, so only setpgrp(0,0) is portable. See also POSIX::setsid() .
Any help is appreciated.