views:

1298

answers:

4

Hello,

I am running a long program in a remote machine, and I want to stop it, but my problem is that if I use the kill command then the program will exit without saving results. Normally what I do to finish the program is using ctrl c and in that case the program saves the results, but right now I am not in the machine that is running the session so I cannot do ctrl c.

My question is: is there any way to do in a remote way the equivalent of ctrl c?.

+7  A: 

Try:

kill -SIGINT processPIDHere

Basically Ctrl C sends the SIGINT (interrupt) signal while kill sends the SIGTERM (termination) signal by default unless you specify the signal to send.

Firas Assaad
+3  A: 

ctrl c just sends a SIGINT signal, but there is some other signals that is a little more soft. 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)

/Johan

Johan
Upps Firas Assad beat me with 35seconds...
Johan
Voted down for wrong information which even contradicts the whole question. Ctrl+C doesn't send SIGKILL. SIGKILL makes the kernel kill the process w/o even sending any signal to the process beforehand anymore.
ypnos
@ypnos, you are quite right, ctrl+c don't send a sigkill. But the error is corrected by "mgb".
Johan
Yes, that's why I came back to change the vote as soon as it's fixed.
ypnos
+1  A: 

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 thing to do.

dmckee
A: 

Keep in mind as well in your signal handler, that it is like an interrupt handler in that you are very limited as to what you are allowed to do in it without corrupting the rest of your program. The best thing you can do here is set an atomic_t "should_quit" variable.

Paul Betts