Replies: 1 comment 1 reply
-
There's no mechanism in the SSH protocol to query PID information of remote processes. That whole concept is somewhat OS-specific. However, here are a few ideas on this: If you are running OpenSSH 7.9 or later as the server, you can use the terminate() or kill() methods on an AsyncSSH channel or process to kill a remote process, or more generally the send_signal() method to send other signals. Some other SSH servers support this as well, but OpenSSH specifically didn't support it before version 7.9 See OpenSSH bug 1424 for details. Another option would be to request a PTY when you start the remote process. If that process is run in the foreground, you should be able to send a Ctrl-C on the channel to stop it. Finally, it's less pretty but you could run a remote command which leveraged a shell to start up a process and output the PID of that process, and you could read that output in your AsyncSSH client. Then, when you needed to kill the process, you could open a new SSH session to send a "kill" command to the remote system with that PID. As for waiting for a process to terminate, there's a wait() method in AsyncSSH's SSHClientProcess which can do this. You can also wait for EOF on stdout/stderr on the remote process, if you are reading output yourself rather than using something like run(). |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am building an web server which start remote ssh-processes when endpoints are called.
Now it may happen that a session terminated and a remote process is still running, but should also be stopped. Therefore i want to store its pid to be able to kill it afterwards on the remote machine.
Is there a way to start a async remote process and get its pid and then await (non-blocking) for the remote-process to terminate?
Beta Was this translation helpful? Give feedback.
All reactions