How to terminate a python process similar to ctrl-c?
up vote
0
down vote
favorite
If I have several Terminal windows open, each running a python script, is there a way to terminate one by PID as if I pressed ctrl-c?
With ctrl-c the script exits gracefully, but I tried various kill -s commands and they all caused it to terminate without catching the script's main (infinite) while loop.
There are some 'cleanup' actions that get performed after ctrl-c.
bash terminal python
add a comment |
up vote
0
down vote
favorite
If I have several Terminal windows open, each running a python script, is there a way to terminate one by PID as if I pressed ctrl-c?
With ctrl-c the script exits gracefully, but I tried various kill -s commands and they all caused it to terminate without catching the script's main (infinite) while loop.
There are some 'cleanup' actions that get performed after ctrl-c.
bash terminal python
1
kill -2 PIDis equivalent toCtrl-C, but I don't know if they will break into a CPU loop.
– AFH
Nov 15 at 15:31
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
If I have several Terminal windows open, each running a python script, is there a way to terminate one by PID as if I pressed ctrl-c?
With ctrl-c the script exits gracefully, but I tried various kill -s commands and they all caused it to terminate without catching the script's main (infinite) while loop.
There are some 'cleanup' actions that get performed after ctrl-c.
bash terminal python
If I have several Terminal windows open, each running a python script, is there a way to terminate one by PID as if I pressed ctrl-c?
With ctrl-c the script exits gracefully, but I tried various kill -s commands and they all caused it to terminate without catching the script's main (infinite) while loop.
There are some 'cleanup' actions that get performed after ctrl-c.
bash terminal python
bash terminal python
asked Nov 15 at 15:25
Ze'ev
83631537
83631537
1
kill -2 PIDis equivalent toCtrl-C, but I don't know if they will break into a CPU loop.
– AFH
Nov 15 at 15:31
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47
add a comment |
1
kill -2 PIDis equivalent toCtrl-C, but I don't know if they will break into a CPU loop.
– AFH
Nov 15 at 15:31
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47
1
1
kill -2 PID is equivalent to Ctrl-C, but I don't know if they will break into a CPU loop.– AFH
Nov 15 at 15:31
kill -2 PID is equivalent to Ctrl-C, but I don't know if they will break into a CPU loop.– AFH
Nov 15 at 15:31
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Typing CtrlC generates signal number 2 (SIGINT). The same signal is generated by:
kill -2 PID
or:
kill -SIGINT PID
You can list all the signal numbers and names with:
kill -l
1
Or justkill -INT PIDfor short!
– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that theSIGprefix is optional.
– AFH
Nov 16 at 11:40
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Typing CtrlC generates signal number 2 (SIGINT). The same signal is generated by:
kill -2 PID
or:
kill -SIGINT PID
You can list all the signal numbers and names with:
kill -l
1
Or justkill -INT PIDfor short!
– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that theSIGprefix is optional.
– AFH
Nov 16 at 11:40
add a comment |
up vote
1
down vote
accepted
Typing CtrlC generates signal number 2 (SIGINT). The same signal is generated by:
kill -2 PID
or:
kill -SIGINT PID
You can list all the signal numbers and names with:
kill -l
1
Or justkill -INT PIDfor short!
– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that theSIGprefix is optional.
– AFH
Nov 16 at 11:40
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Typing CtrlC generates signal number 2 (SIGINT). The same signal is generated by:
kill -2 PID
or:
kill -SIGINT PID
You can list all the signal numbers and names with:
kill -l
Typing CtrlC generates signal number 2 (SIGINT). The same signal is generated by:
kill -2 PID
or:
kill -SIGINT PID
You can list all the signal numbers and names with:
kill -l
answered Nov 15 at 16:00
AFH
13.4k31938
13.4k31938
1
Or justkill -INT PIDfor short!
– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that theSIGprefix is optional.
– AFH
Nov 16 at 11:40
add a comment |
1
Or justkill -INT PIDfor short!
– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that theSIGprefix is optional.
– AFH
Nov 16 at 11:40
1
1
Or just
kill -INT PID for short!– Shou Ya
Nov 16 at 6:34
Or just
kill -INT PID for short!– Shou Ya
Nov 16 at 6:34
@ShouYa - Thanks, I'd forgotten that the
SIG prefix is optional.– AFH
Nov 16 at 11:40
@ShouYa - Thanks, I'd forgotten that the
SIG prefix is optional.– AFH
Nov 16 at 11:40
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1375721%2fhow-to-terminate-a-python-process-similar-to-ctrl-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
kill -2 PIDis equivalent toCtrl-C, but I don't know if they will break into a CPU loop.– AFH
Nov 15 at 15:31
@AFH Yes, that did it! Accepted answer!
– Ze'ev
Nov 15 at 15:47