I want ssh to forward the SIGTERM signal to the remote command. Example: ssh root at localhost /root/print-signal.py Get PID of ssh: ps aux| grep print-signal Kill the matching ssh process: kill pid-of-ssh Unfortunately only the ssh process itself gets the signal, not the remote command (print-signal.py). The remote command does not terminate :-( How can I make ssh "forward" the SIGTERM signal to the remote command? See https://stackoverflow.com/questions/48377993/forwards-sigterm-over-ssh According to this[1] answer, openssh does not implement this. It would be realy great if openssh could forward the signal to the remote-command. What do you think? Regards, Thomas G?ttler [1] https://stackoverflow.com/questions/46333657/send-signals-to-remote-process-with-python/47581495#47581495 -- Thomas Guettler http://www.thomas-guettler.de/ I am looking for feedback: https://github.com/guettli/programming-guidelines
On January 23, 2018 6:13 AM, Thomas G?ttler wrote:> > I want ssh to forward the SIGTERM signal to the remote command. > > > Example: > ssh root at localhost /root/print-signal.py > > > Get PID of ssh: > ps aux| grep print-signal > > > Kill the matching ssh process: > kill pid-of-ssh > > > Unfortunately only the ssh process itself gets the signal, not the remote > command (print-signal.py). The remote command does not terminate :-( > > How can I make ssh "forward" the SIGTERM signal to the remote command? > > See https://stackoverflow.com/questions/48377993/forwards-sigterm-over- > ssh > > According to this[1] answer, openssh does not implement this. > > It would be realy great if openssh could forward the signal to the remote- > command. > > What do you think?Would you consider using a separate SSH session to get to the lower level process, along the lines of ssh root at localhost 'kill -signum pid-of-py' Or is this not the use case you're looking for. Cheers, Randall -- Brief whoami: NonStop developer since approximately 211288444200000000 UNIX developer since approximately 421664400 -- In my real life, I talk too much.
Thomas G?ttler wrote:> Example: > ssh root at localhost /root/print-signal.py > > Get PID of ssh: > ps aux| grep print-signal > > Kill the matching ssh process: > kill pid-of-ssh > > Unfortunately only the ssh process itself gets the signal, not the > remote command (print-signal.py). The remote command does not > terminate :-( > > How can I make ssh "forward" the SIGTERM signal to the remote command? > > See https://stackoverflow.com/questions/48377993/forwards-sigterm-over-ssh > > According to this[1] answer, openssh does not implement this.Correct, that channel message is currently not supported by OpenSSH.> It would be realy great if openssh could forward the signal to the > remote-command.Yes and no. I agree that sending signals to remote processes (channels, actually) can be very useful. But I absolutely do not want to lose the ability to send signals to the ssh client itself on the system where it is running. So "remote signals" need to be separate from local signals - meaning that they probably need some other interface than kill(). This gets complicated. How do you know which channel to send the signal to? One ssh process can have many open channels. So whatever interface is used would possibly also have to allow enumerating open channels, but obviously only for the respectiveuser. How to accomplish that in a portable manner? Maybe a AF_UNIX socket with a custom protocol? I don't think there exists any development for such an interface, and it's not a trivial thing. Meanwhile, what you can do is make /root/print-signal.py on the output its own pid to stdout which you save in your software/script on the client side, and open a second channel (e.g. using multiplexing): ssh root at localhost 'kill -TERM insert_pid_here' which sends the signal. This expands on the second point in the stackoverflow answer. //Peter
Perhaps a multi-step process. How about... After you have PID of the ssh session, run a second query looking for the PID of processes that have PPID equals the remote ssh PID just found. Sent from my iPhone> On 23 Jan 2018, at 15:33, Peter Stuge <peter at stuge.se> wrote: > > Thomas G?ttler wrote: >> Example: >> ssh root at localhost /root/print-signal.py >> >> Get PID of ssh: >> ps aux| grep print-signal >> >> Kill the matching ssh process: >> kill pid-of-ssh >> >> Unfortunately only the ssh process itself gets the signal, not the >> remote command (print-signal.py). The remote command does not >> terminate :-( >> >> How can I make ssh "forward" the SIGTERM signal to the remote command? >> >> See https://stackoverflow.com/questions/48377993/forwards-sigterm-over-ssh >> >> According to this[1] answer, openssh does not implement this. > > Correct, that channel message is currently not supported by OpenSSH. > > >> It would be realy great if openssh could forward the signal to the >> remote-command. > > Yes and no. > > I agree that sending signals to remote processes (channels, actually) > can be very useful. > > But I absolutely do not want to lose the ability to send signals to > the ssh client itself on the system where it is running. > > So "remote signals" need to be separate from local signals - meaning > that they probably need some other interface than kill(). > > This gets complicated. How do you know which channel to send the > signal to? One ssh process can have many open channels. > > So whatever interface is used would possibly also have to allow > enumerating open channels, but obviously only for the respectiveuser. > > How to accomplish that in a portable manner? Maybe a AF_UNIX socket > with a custom protocol? > > I don't think there exists any development for such an interface, and > it's not a trivial thing. > > > Meanwhile, what you can do is make /root/print-signal.py on the > output its own pid to stdout which you save in your software/script > on the client side, and open a second channel (e.g. using multiplexing): > > ssh root at localhost 'kill -TERM insert_pid_here' > > which sends the signal. > > This expands on the second point in the stackoverflow answer. > > > //Peter > > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev >
El martes, 23 de enero de 2018, Thomas G?ttler <guettliml at thomas-guettler.de> escribi?:> I want ssh to forward the SIGTERM signal to the remote command. > > > Example: > ssh root at localhost /root/print-signal.py > > > Get PID of ssh: > ps aux| grep print-signal > > > Kill the matching ssh process: > kill pid-of-ssh > > > Unfortunately only the ssh process itself gets the signal, not the remote > command (print-signal.py). The remote command does not terminate :-( > > How can I make ssh "forward" the SIGTERM signal to the remote command? > > See https://stackoverflow.com/questions/48377993/forwards-sigterm-over-ssh > > According to this[1] answer, openssh does not implement this. > > It would be realy great if openssh could forward the signal to the > remote-command. > > What do you think? > > Regards, > Thomas G?ttler > > > [1] https://stackoverflow.com/questions/46333657/send-signals- > to-remote-process-with-python/47581495#47581495 > > > > -- > Thomas Guettler http://www.thomas-guettler.de/ > I am looking for feedback: https://github.com/guettli/pro > gramming-guidelines > > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev >
On Tue, 23 Jan 2018, Thomas G?ttler wrote:> > I want ssh to forward the SIGTERM signal to the remote command. > > Example: > ssh root at localhost /root/print-signal.py > > Get PID of ssh: > ps aux| grep print-signal > > Kill the matching ssh process: > kill pid-of-sshYou might be able to get around it by running: $ ssh root at localhost '/root/print-signal.py </dev/null >/dev/null 2>/dev/null' I recall I used that in another context. I also recall the `ssh' command not returning the prompt. Does that allso happen to you? Cheers, -- Cristian
Well, it would be nice to do ssh remote print-signal.py and then ssh remote pkill print-signal.py This should work for your way of getting pid but beware when you have two or more instances that could be running and want selective killing. Instead a pkill calling and the use of pgrep I like to write a pagre and peca like so bin/pagre #!/bin/bash ps -A | grep $1 bin/peca #!/bin/bash pgrep $@ | cut -d" " -f2 | xargs kill -9 so you will have to do ssh remote peca print-signal.py cheers carlos El martes, 23 de enero de 2018, Thomas G?ttler <guettliml at thomas-guettler.de> escribi?:> I want ssh to forward the SIGTERM signal to the remote command. > > > Example: > ssh root at localhost /root/print-signal.py > > > Get PID of ssh: > ps aux| grep print-signal > > > Kill the matching ssh process: > kill pid-of-ssh > > > Unfortunately only the ssh process itself gets the signal, not the remote > command (print-signal.py). The remote command does not terminate :-( > > How can I make ssh "forward" the SIGTERM signal to the remote command? > > See https://stackoverflow.com/questions/48377993/forwards-sigterm-over-ssh > > According to this[1] answer, openssh does not implement this. > > It would be realy great if openssh could forward the signal to the > remote-command. > > What do you think? > > Regards, > Thomas G?ttler > > > [1] https://stackoverflow.com/questions/46333657/send-signals-to > -remote-process-with-python/47581495#47581495 > > > > -- > Thomas Guettler http://www.thomas-guettler.de/ > I am looking for feedback: https://github.com/guettli/pro > gramming-guidelines > > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev >
Am 23.01.2018 um 18:24 schrieb Cristian Ionescu-Idbohrn:> On Tue, 23 Jan 2018, Thomas G?ttler wrote: >> >> I want ssh to forward the SIGTERM signal to the remote command. >> >> Example: >> ssh root at localhost /root/print-signal.py >> >> Get PID of ssh: >> ps aux| grep print-signal >> >> Kill the matching ssh process: >> kill pid-of-ssh > > You might be able to get around it by running: > > $ ssh root at localhost '/root/print-signal.py </dev/null >/dev/null 2>/dev/null' > > I recall I used that in another context. I also recall the `ssh' > command not returning the prompt. Does that allso happen to you?I tried this, and it did not help. I ask myself how this could help, since the ssh does not forward the signal. Do you think closing the streams make a difference? Regards, Thomas -- Thomas Guettler http://www.thomas-guettler.de/ I am looking for feedback: https://github.com/guettli/programming-guidelines
Thomas Güttler
2018-Jan-24 08:45 UTC
kill (work-around) does not wait. Was: Sending Signal to remote process
Am 24.01.2018 um 04:56 schrieb Carlos Morel G?mez La Roque:> Well, it would be nice to do > > ssh remote print-signal.py > > and then > > ssh remote pkill print-signal.py >Yes, I could work around this by killing the remote command myself. But "kill" or "pkill" have one big disadvantage in this case: It does not wait until the remote command has terminated. But this is off-topic here. If you curious, I asked this question here: https://unix.stackexchange.com/questions/419284/pkill-which-waits Regards, Thomas G?ttler -- Thomas Guettler http://www.thomas-guettler.de/ I am looking for feedback: https://github.com/guettli/programming-guidelines