why sometime need to stop process by kill -9












0














we have kafka machines in hadoop cluster



the script that stop the kafka process do the following



kill PID



but we notice that the script that stop the kafka not really kill the process



therefore we killed it ( manually ) by:



kill -9 PID



so - in which cases process insist to killed by -9 ( instead just kill pid )



example from the script



function kafkaKill {
local localPID=$1
kill $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

kill -s KILL $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

return 1
}









share|improve this question
























  • This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
    – Panki
    14 mins ago










  • I prefer to get clear answer , if you think your answer fit for my question then please post it
    – yael
    11 mins ago
















0














we have kafka machines in hadoop cluster



the script that stop the kafka process do the following



kill PID



but we notice that the script that stop the kafka not really kill the process



therefore we killed it ( manually ) by:



kill -9 PID



so - in which cases process insist to killed by -9 ( instead just kill pid )



example from the script



function kafkaKill {
local localPID=$1
kill $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

kill -s KILL $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

return 1
}









share|improve this question
























  • This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
    – Panki
    14 mins ago










  • I prefer to get clear answer , if you think your answer fit for my question then please post it
    – yael
    11 mins ago














0












0








0







we have kafka machines in hadoop cluster



the script that stop the kafka process do the following



kill PID



but we notice that the script that stop the kafka not really kill the process



therefore we killed it ( manually ) by:



kill -9 PID



so - in which cases process insist to killed by -9 ( instead just kill pid )



example from the script



function kafkaKill {
local localPID=$1
kill $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

kill -s KILL $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

return 1
}









share|improve this question















we have kafka machines in hadoop cluster



the script that stop the kafka process do the following



kill PID



but we notice that the script that stop the kafka not really kill the process



therefore we killed it ( manually ) by:



kill -9 PID



so - in which cases process insist to killed by -9 ( instead just kill pid )



example from the script



function kafkaKill {
local localPID=$1
kill $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

kill -s KILL $localPID || return 1
for ((i=0; i<MAX_WAIT_TIME; i++)); do
kafkaIsRunning $localPID
if [ $? -eq 0 ]; then return 0; fi
sleep 1
done

return 1
}






linux process kill ps hadoop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 14 mins ago

























asked 20 mins ago









yael

2,43112362




2,43112362












  • This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
    – Panki
    14 mins ago










  • I prefer to get clear answer , if you think your answer fit for my question then please post it
    – yael
    11 mins ago


















  • This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
    – Panki
    14 mins ago










  • I prefer to get clear answer , if you think your answer fit for my question then please post it
    – yael
    11 mins ago
















This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
– Panki
14 mins ago




This might help you out (SIGTERM is what kill sends by default): unix.stackexchange.com/questions/195998/…
– Panki
14 mins ago












I prefer to get clear answer , if you think your answer fit for my question then please post it
– yael
11 mins ago




I prefer to get clear answer , if you think your answer fit for my question then please post it
– yael
11 mins ago










1 Answer
1






active

oldest

votes


















0














Sending a standard kill to a process sends (according to wikipedia) a SIGTERM by default. What this does is notify the process that it should shut down. This is the nice way of dealing with the process, and it goes like this:




  • Process registers signal handler for SIGTERM

  • You want to kill the process

  • You send SIGTERM through kill

  • The signal handler is called, this is the chance for the process to


    • Close files that it has open

    • Write out any buffers

    • Shut down any child threads




There's nothing in sending a SIGTERM that forces a process to exit. It can completely ignore it or it can behave however it wants.



Kill -9 sends SIGKILL. You're not allowed to register a handler for SIGKILL, which means the default is called (kernel space I believe - someone correct me here). In this case, you don't have a chance to do the above, your process is immediately removed from the runnable process list and its memory and everything are destroyed. This can clearly cause issues if you were halfway through writing to a file.



Some processes will take multiple SIGTERM signals before they shutdown - have you tried that? The process may also document what signals you can send it to shut it down cleanly.



A process that is in a bad state may not have the chance to get to the signal handler, even if it has one registered. There are points where a signal cannot be received (You're in an interrupt, or already handling another signal, and some others that I can't pinpoint at the moment). IF your process is stuck (for whatever reason) in one of these points, the SIGTERM handler will never run, no matter how many times you send it. The only solution here is a SIGKILL, however I've even seen cases where that signal is ignored, in which case a system reboot is necessary.



Actual answer



To answer your question - in which cases is kill ignored and insist being killed with -9:




  • The process has registered a SIGTERM handler that specifically doesn't kill the process (note - the default SIGTERM will kill the process)

  • The process is stuck in a signal-blocked state where a SIGTERM handler cannot be run





share





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f493019%2fwhy-sometime-need-to-stop-process-by-kill-9%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









    0














    Sending a standard kill to a process sends (according to wikipedia) a SIGTERM by default. What this does is notify the process that it should shut down. This is the nice way of dealing with the process, and it goes like this:




    • Process registers signal handler for SIGTERM

    • You want to kill the process

    • You send SIGTERM through kill

    • The signal handler is called, this is the chance for the process to


      • Close files that it has open

      • Write out any buffers

      • Shut down any child threads




    There's nothing in sending a SIGTERM that forces a process to exit. It can completely ignore it or it can behave however it wants.



    Kill -9 sends SIGKILL. You're not allowed to register a handler for SIGKILL, which means the default is called (kernel space I believe - someone correct me here). In this case, you don't have a chance to do the above, your process is immediately removed from the runnable process list and its memory and everything are destroyed. This can clearly cause issues if you were halfway through writing to a file.



    Some processes will take multiple SIGTERM signals before they shutdown - have you tried that? The process may also document what signals you can send it to shut it down cleanly.



    A process that is in a bad state may not have the chance to get to the signal handler, even if it has one registered. There are points where a signal cannot be received (You're in an interrupt, or already handling another signal, and some others that I can't pinpoint at the moment). IF your process is stuck (for whatever reason) in one of these points, the SIGTERM handler will never run, no matter how many times you send it. The only solution here is a SIGKILL, however I've even seen cases where that signal is ignored, in which case a system reboot is necessary.



    Actual answer



    To answer your question - in which cases is kill ignored and insist being killed with -9:




    • The process has registered a SIGTERM handler that specifically doesn't kill the process (note - the default SIGTERM will kill the process)

    • The process is stuck in a signal-blocked state where a SIGTERM handler cannot be run





    share


























      0














      Sending a standard kill to a process sends (according to wikipedia) a SIGTERM by default. What this does is notify the process that it should shut down. This is the nice way of dealing with the process, and it goes like this:




      • Process registers signal handler for SIGTERM

      • You want to kill the process

      • You send SIGTERM through kill

      • The signal handler is called, this is the chance for the process to


        • Close files that it has open

        • Write out any buffers

        • Shut down any child threads




      There's nothing in sending a SIGTERM that forces a process to exit. It can completely ignore it or it can behave however it wants.



      Kill -9 sends SIGKILL. You're not allowed to register a handler for SIGKILL, which means the default is called (kernel space I believe - someone correct me here). In this case, you don't have a chance to do the above, your process is immediately removed from the runnable process list and its memory and everything are destroyed. This can clearly cause issues if you were halfway through writing to a file.



      Some processes will take multiple SIGTERM signals before they shutdown - have you tried that? The process may also document what signals you can send it to shut it down cleanly.



      A process that is in a bad state may not have the chance to get to the signal handler, even if it has one registered. There are points where a signal cannot be received (You're in an interrupt, or already handling another signal, and some others that I can't pinpoint at the moment). IF your process is stuck (for whatever reason) in one of these points, the SIGTERM handler will never run, no matter how many times you send it. The only solution here is a SIGKILL, however I've even seen cases where that signal is ignored, in which case a system reboot is necessary.



      Actual answer



      To answer your question - in which cases is kill ignored and insist being killed with -9:




      • The process has registered a SIGTERM handler that specifically doesn't kill the process (note - the default SIGTERM will kill the process)

      • The process is stuck in a signal-blocked state where a SIGTERM handler cannot be run





      share
























        0












        0








        0






        Sending a standard kill to a process sends (according to wikipedia) a SIGTERM by default. What this does is notify the process that it should shut down. This is the nice way of dealing with the process, and it goes like this:




        • Process registers signal handler for SIGTERM

        • You want to kill the process

        • You send SIGTERM through kill

        • The signal handler is called, this is the chance for the process to


          • Close files that it has open

          • Write out any buffers

          • Shut down any child threads




        There's nothing in sending a SIGTERM that forces a process to exit. It can completely ignore it or it can behave however it wants.



        Kill -9 sends SIGKILL. You're not allowed to register a handler for SIGKILL, which means the default is called (kernel space I believe - someone correct me here). In this case, you don't have a chance to do the above, your process is immediately removed from the runnable process list and its memory and everything are destroyed. This can clearly cause issues if you were halfway through writing to a file.



        Some processes will take multiple SIGTERM signals before they shutdown - have you tried that? The process may also document what signals you can send it to shut it down cleanly.



        A process that is in a bad state may not have the chance to get to the signal handler, even if it has one registered. There are points where a signal cannot be received (You're in an interrupt, or already handling another signal, and some others that I can't pinpoint at the moment). IF your process is stuck (for whatever reason) in one of these points, the SIGTERM handler will never run, no matter how many times you send it. The only solution here is a SIGKILL, however I've even seen cases where that signal is ignored, in which case a system reboot is necessary.



        Actual answer



        To answer your question - in which cases is kill ignored and insist being killed with -9:




        • The process has registered a SIGTERM handler that specifically doesn't kill the process (note - the default SIGTERM will kill the process)

        • The process is stuck in a signal-blocked state where a SIGTERM handler cannot be run





        share












        Sending a standard kill to a process sends (according to wikipedia) a SIGTERM by default. What this does is notify the process that it should shut down. This is the nice way of dealing with the process, and it goes like this:




        • Process registers signal handler for SIGTERM

        • You want to kill the process

        • You send SIGTERM through kill

        • The signal handler is called, this is the chance for the process to


          • Close files that it has open

          • Write out any buffers

          • Shut down any child threads




        There's nothing in sending a SIGTERM that forces a process to exit. It can completely ignore it or it can behave however it wants.



        Kill -9 sends SIGKILL. You're not allowed to register a handler for SIGKILL, which means the default is called (kernel space I believe - someone correct me here). In this case, you don't have a chance to do the above, your process is immediately removed from the runnable process list and its memory and everything are destroyed. This can clearly cause issues if you were halfway through writing to a file.



        Some processes will take multiple SIGTERM signals before they shutdown - have you tried that? The process may also document what signals you can send it to shut it down cleanly.



        A process that is in a bad state may not have the chance to get to the signal handler, even if it has one registered. There are points where a signal cannot be received (You're in an interrupt, or already handling another signal, and some others that I can't pinpoint at the moment). IF your process is stuck (for whatever reason) in one of these points, the SIGTERM handler will never run, no matter how many times you send it. The only solution here is a SIGKILL, however I've even seen cases where that signal is ignored, in which case a system reboot is necessary.



        Actual answer



        To answer your question - in which cases is kill ignored and insist being killed with -9:




        • The process has registered a SIGTERM handler that specifically doesn't kill the process (note - the default SIGTERM will kill the process)

        • The process is stuck in a signal-blocked state where a SIGTERM handler cannot be run






        share











        share


        share










        answered 4 mins ago









        Brydon Gibson

        13216




        13216






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493019%2fwhy-sometime-need-to-stop-process-by-kill-9%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

            濃尾地震

            How to rewrite equation of hyperbola in standard form

            No ethernet ip address in my vocore2