30

I have setup a run configuration in Eclipse and need to send SIGINT (Ctrl+C) to the program. There is cleanup code in the program that runs after SIGINT, so pressing Eclipse's "Terminate" buttons won't work (they send SIGKILL I think). Typing CTRL+C into the Console also doesn't work.

How do I send SIGINT to a process running inside an Eclipse Console?

(FWIW I am running a Twisted daemon and need Twisted to shutdown correctly, which only occurs on SIGINT)

Mwiza
  • 7,780
  • 3
  • 46
  • 42
vsekhar
  • 5,090
  • 5
  • 22
  • 23

5 Answers5

9

If you can determine the process with a utility such as ps, you can use kill to send it a SIGINT. The program will likely be a child process of eclipse.

kill -s INT <pid>
jordanm
  • 33,009
  • 7
  • 61
  • 76
  • 1
    Right now I use `kill -INT \`pgrep python\`` so I don't have to muck around finding pids, but even that is a bit cumbersome for rapid code/debug cycles. – vsekhar Jan 16 '12 at 04:21
  • 1
    You can shorten that to `pkill -INT python`, if you don't mind all python processes being killed. – jordanm Jan 16 '12 at 15:35
  • 1
    So the point of the question is that kill+pgrep or pkill are blunt instruments (and there are in fact other python processes running that will get clobbered). I'm hoping for a more fine-grained approach, and CTRL-C via Eclipse seems like it should be possible. – vsekhar Jan 16 '12 at 21:16
  • I understand I am not directly solving your problem, but you can use pkill -f, along with stricter matching to ensure that SIGINT is only sent to the script you want. – jordanm Jan 16 '12 at 21:49
  • Uri: Well, SIGINT is a UNIX signal. – jordanm Apr 30 '12 at 13:52
2

You can send the command via one line:

 kill -SIGINT $(ps aux | grep ProgrammName | grep -v grep | awk '{print $2}') 

Get the process id and than send the sigint signal

John Smithv1
  • 673
  • 5
  • 14
  • 33
0

That still seems to be an open issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016

Just for the sake of completeness: If you came here to find a way to terminate a read line from System.in, Ctrl + Z worked for me (on Windows).

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
  • Are you really talking about the _eclipse_ console? I can't confirm that for my Windows system: when hitting _Ctrl_ + _Z_ in the console view nothing happens. – Tobias Liefke Oct 04 '18 at 11:57
  • Maybe I configured my runtime differently back then: https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016#c1 – Jens Piegsa Oct 04 '18 at 13:56
  • The mentioned comment talks about _Ctrl_ + _C_ and even that one was not available since 2006, see [comment 11](https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016#c11) – Tobias Liefke Oct 05 '18 at 06:50
  • Let me try to reconstruct this: I think back then, I needed a way to terminate a read line from System.in. That's indeed a different problem, which was solved by pressing Ctrl + Z (EOF). It was mentioned in a comment by Bizmarck on jordanm's answer. Sorry for the confusion. I updated my answer accordingly. – Jens Piegsa Oct 05 '18 at 08:08
0

in some versions, you can do the following.

In the Debug perspective, you can open a view called "Signals" (Window/Show View/Signals" or Left-Bottom Icon).

You will get a list of all supported signals. Right-click and "Resume with Signal" will give you the result you need.

avish
  • 48
  • 6
0

I'm making an answer out of a modification of Artur Czajka's comment.

You can use pkill -SIGINT -f ProgramName. Explanation: pkill is similar to killall, -SIGINT states the signal to be used, -f makes it work better in this case (it will look through arguments and stuff instead of just the command name), and ProgramName is the target for pkill.

TheTechRobo the Nerd
  • 1,249
  • 15
  • 28