Equivalent of ctrl c in command to cancel a program

LinuxCommand LineCopy Paste

Linux Problem Overview


I am running a long linux 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 use 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 press Ctrl+C.

My question is: is there any way to do in a remote way the equivalent of Ctrl+C?

Linux Solutions


Solution 1 - Linux

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.

Solution 2 - Linux

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)

Solution 3 - Linux

Here's an example for mongod

To start the daemon from the command line:

mongod &

Then later

kill -SIGINT `pgrep mongod`

Solution 4 - Linux

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.

Solution 5 - Linux

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.

Solution 6 - Linux

I am doing as below way

killall -2 <ProgramName>

or

kill -2 <PID of your process>

I used to forget the the name of signal. i.e SIGINT/SIGKILL here so i am using number for that like killall -2 or killall -9

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEduardoView Question on Stackoverflow
Solution 1 - LinuxFiras AssaadView Answer on Stackoverflow
Solution 2 - LinuxJohanView Answer on Stackoverflow
Solution 3 - LinuxMichael ColeView Answer on Stackoverflow
Solution 4 - Linuxdmckee --- ex-moderator kittenView Answer on Stackoverflow
Solution 5 - LinuxAna BettsView Answer on Stackoverflow
Solution 6 - LinuxJeegar PatelView Answer on Stackoverflow