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.










share|improve this question


















  • 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












  • @AFH Yes, that did it! Accepted answer!
    – Ze'ev
    Nov 15 at 15:47















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.










share|improve this question


















  • 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












  • @AFH Yes, that did it! Accepted answer!
    – Ze'ev
    Nov 15 at 15:47













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 at 15:25









Ze'ev

83631537




83631537








  • 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












  • @AFH Yes, that did it! Accepted answer!
    – Ze'ev
    Nov 15 at 15:47














  • 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












  • @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










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





share|improve this answer

















  • 1




    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











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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





share|improve this answer

















  • 1




    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















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





share|improve this answer

















  • 1




    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













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





share|improve this answer












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






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 at 16:00









AFH

13.4k31938




13.4k31938








  • 1




    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














  • 1




    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








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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Terni

A new problem with tex4ht and tikz

Sun Ra