3

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.

Ole Tange
  • 5,099

1 Answers1

0

Do you really need a tty?

You could just use ssh server killall burnP6 is there is just one process with such name.

Or you could somehow write the IP of your process in a file and then use something like `ssh server kill $(cat /tmp/burnP6.pid)".

Or a simpler and more robust implementation would be to use the package daemon, meant to daemonize otherwise non-daemon-featured programs. It lets you automatically write your daemon's PID to a file and kill it easily. It can even relaunch your process in case it dies.

To start it:

ssh server daemon -n burnP6 -- /usr/bin/burnP6

To stop it:

ssh server daemon --stop -n burnP6