|
General software and network General OS-independent software and network questions, X11, MTA, routing, etc. |
|
Thread Tools | Display Modes |
|
|||
Returning the PID of a ssh process
How do you get the PID of a backgrounded ('-f ') ssh process?
|
|
|||
There will be other ssh instances running, I'd have to parse the command line arguments.
pgrep with '-x' and '-n' flags after pausing the script a few milliseconds is what I have been doing. Last edited by gso; 14th September 2015 at 02:56 PM. |
|
|||
ssh -D 1080 -CNf -o ExitOnForwardFailure=yes user@host... && pgrep -x -n ssh
Seems to work quite reliably. Having said that there is only ever going to be one ssh process listening on 1080. |
|
|||
ssh -D 1080 -CNf -o ExitOnForwardFailure=yes user@host... && pgrep -f 'ssh -D 1080'
|
|
|||
For ssh not to have the usual command line option to write the PID to a file, there would have to be a reason?
Last edited by gso; 14th September 2015 at 06:15 PM. |
|
|||
ssh -O stop server1
ssh -O cancel -L 8080:localhost:80 -S ~/.ssh/controlmaster/fred@server.example.org:22 server.example.org https://en.wikibooks.org/wiki/OpenSS...k/Multiplexing There are however caveats: http://www.anchor.com.au/blog/2010/0...-bad-the-ugly/ [Edit: if there were only one connection per socket then I can't see there would be any issues.] Last edited by gso; 14th September 2015 at 04:56 PM. |
|
|||
[djm [at] demiurg ~]$ ssh -nNfS ~/ctl-sock-blah localhost
[djm [at] demiurg ~]$ ssh -S ~/ctl-sock-blah -O check localhost Master running (pid=3517) [djm [at] demiurg ~]$ ssh -S ~/ctl-sock-blah -O exit localhost Exit request sent. http://www.gossamer-threads.com/lists/openssh/dev/48040 By no means a new topic. |
|
|||
I am using ssh-agent at the moment anyway, '-f' isn't strictly necessary
ssh -D 1080 -CN user@host... & echo $! |
|
|||
Still can't help wondering what the folks over at OpenSSH really had against the patch proposal, OpenBSD folk can be a bit odd at times (a reputation which doesn't seem to bother them) but never-the-less I don't think would act without good reason.
|
|
|||
If you want to know if a process is still running OK (or likewise close a ssh connection) then a PID is not the way to do it, the control socket will do the job.
[Edit: the man page could be a bit more helpful, it's one thing having the tools, but the tools and the techniques and skills is actually what is needed.] Last edited by gso; 14th September 2015 at 05:37 PM. |
|
||||
The "folks" with this particular determination were just one: Damien Miller. He's the "djm" in the mailing list history you linked in post #12. He is still the lead developer for OpenSSH.
It's possible Damien may be willing to revisit the issue, if there is some reason the ControlMaster option cannot be used. You could always ask him. I don't see the caveats as critical, because they are related to TCP session performance and master session control. Neither should be an issue if you enable ControlMaster and set unique ControlSockets for each background shell you wish to manage. Another alternative is using a getppid(2) syscall from the background shell, as I'd originally envisioned you needed. |
|
|||
If I submit a patch it will be to the man page.
|
|
|||
A rc script duly implementing the above http://daemonforums.org/showthread.php?t=9384
As to the man page, the '-O' flag is described as: Code:
-O ctl_cmd Control an active connection multiplexing master process. When the -O option is specified, the ctl_cmd argument is interpreted and passed to the master process. Valid commands are: ``check'' (check that the master process is running), ``forward'' (request forwardings without command execution), ``cancel'' (cancel for- wardings), ``exit'' (request the master to exit), and ``stop'' (request the master to stop accepting further multiplexing requests). Quote:
|
|
|||
I think I see your point about using the ppid:
Code:
pgrep -P $$ -x ssh Code:
ps -o lstart= -p PID |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OpenBSD 5.7 Update Process | Peter_APIIT | OpenBSD General | 8 | 9th September 2015 01:53 PM |
PhotoRec process bug | LeFrettchen | General software and network | 4 | 1st July 2014 11:15 PM |
returning newbie questions | jimbus | FreeBSD Installation and Upgrading | 6 | 22nd June 2012 02:19 AM |
Help with pthread_create not returning | Darwimy | Programming | 1 | 16th December 2010 07:07 PM |
Loader, MBR and the boot process | Jago | FreeBSD Installation and Upgrading | 1 | 22nd January 2010 04:52 AM |