I’m trying to end a long linux program that’s running on a distant system, but using the kill command causes the program to exit without preserving its results. Normally, I use Ctrl+C to finish a program, and the software saves the results, but I am not in the machine that is running the session right now, so I can’t use Ctrl+C.
My question is, is there a method to execute the equivalent of Ctrl+C from afar?
Asked by Eduardo
kill -SIGINT processPIDHere
Basically, unless you specify otherwise, Ctrl C transmits the SIGINT (interrupt) signal and kill delivers the SIGTERM (termination) signal.
Answered by Firas Assaad
The ctrl c key only sends a SIGINT signal, although there are some additional signals that are softer. http://www.gnu.org/software/libtool/manual/libc/Termination-Signals.html
I think that you can use the the kill command to send some other signal. (see man kill for more info)
Answered by Johan
Here’s a mongod example.
To run the daemon from the command prompt, type:
kill -SIGINT `pgrep mongod`
Answered by Michael Cole
If you control the long-running remote process, you could install a signal handler for SIGTERM (see man signal and man sigaction and the many SO questions on this topic), to cleanup nicely before dieing.
That is a very common occurrence.
Answered by dmckee — ex-moderator kitten
Keep in mind that your signal handler is similar to an interrupt handler in that you are limited in what you can do in it without causing problems elsewhere in your program. Setting an atomic t “should quit” variable is the best option here.
Answered by Ana Betts
Post is based on https://stackoverflow.com/questions/514771/equivalent-of-ctrl-c-in-command-to-cancel-a-program