3
2
This is the general version of: Send SIGTERM signal to a process running inside ssh
It is possible to send Ctrl-C to the remote process if the process gets a pty (-tt):
# Runs for 5 seconds
(sleep 5; echo '^C'; sleep 5) | time ssh -tt localhost burnP6
I had hoped the same would work for Ctrl-Z, but, alas, no:
# Continues to run - does not suspend
(sleep 5; echo '^Z'; sleep 5) | time ssh -tt localhost burnP6
If I get an interactive session, Ctrl-C and Ctrl-Z work fine.
Is there a way I can send other signals (I am especially interested in Ctrl-Z)?
I cannot use the suggested "ssh hostname 'kill -TERM $pid'" as I do not know the pids on the remote system.
What do you mean by "(sleep 5; echo '^C'; sleep 5)"? – Raúl Salinas-Monteagudo – 2014-10-27T13:29:22.487
Wait 5 seconds. Send Ctrl-C (ASCII character 3, type Ctrl-V Ctrl-C in Bash). Wait 5 seconds. – Ole Tange – 2014-10-27T14:33:26.387
But echoing '^C' does not generate a SIGINT signal. You mean it is pseudocode for doing that by hand? – Raúl Salinas-Monteagudo – 2014-10-27T15:51:14.587
1It does generate INT on the remote if you use ssh -tt. So no: It is not pseudocode. The above example with ^C actually works. – Ole Tange – 2014-10-27T19:32:02.693
Note that Ctrl-Z sends a SIGTSTP, not a SIGTERM. Even if you get Ctrl-Z working you're limited to Ctrl-C, Ctrl-, and Ctrl-Z, not arbitrary signals.
– dimo414 – 2017-03-29T08:09:18.583