Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Perlmonks-

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):

UID PID PPID PGID SID CMD root 22409 4763 4763 4763 sshd -f /etc/ssh/sshd_config -R user 22411 22409 22411 22411 tail -f /etc/passwd

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:

UID PID PPID PGID SID CMD user 22411 1 22411 22411 tail -f /etc/passwd

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:

PID - Child's process ID PGRP - Parents process group

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.

Thanks!

-Craig


In reply to Unwanted SSH child survives after ssh session by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found