Does `kill ` figure out the correct order of killing (or does it do proper retrying)?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Some processes can't be killed before other processes, so I can think of a case in which kill <PID list> tries to kill such a process, gives up, then kills its "partner" successfully leaving the former unkilled even though it could have killed it too, had it retried later.



If this case is true, another question would be, does kill <PID list> obey the order of PIDs in my list or do I have to use separate kill processes to control the order in which processes get killed?







share|improve this question
















  • 1




    What do you mean with "Some processes can't be killed before other processes"?
    – dr01
    Feb 7 at 8:56






  • 2




    I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
    – Giacomo Catenazzi
    Feb 7 at 9:50














up vote
0
down vote

favorite












Some processes can't be killed before other processes, so I can think of a case in which kill <PID list> tries to kill such a process, gives up, then kills its "partner" successfully leaving the former unkilled even though it could have killed it too, had it retried later.



If this case is true, another question would be, does kill <PID list> obey the order of PIDs in my list or do I have to use separate kill processes to control the order in which processes get killed?







share|improve this question
















  • 1




    What do you mean with "Some processes can't be killed before other processes"?
    – dr01
    Feb 7 at 8:56






  • 2




    I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
    – Giacomo Catenazzi
    Feb 7 at 9:50












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Some processes can't be killed before other processes, so I can think of a case in which kill <PID list> tries to kill such a process, gives up, then kills its "partner" successfully leaving the former unkilled even though it could have killed it too, had it retried later.



If this case is true, another question would be, does kill <PID list> obey the order of PIDs in my list or do I have to use separate kill processes to control the order in which processes get killed?







share|improve this question












Some processes can't be killed before other processes, so I can think of a case in which kill <PID list> tries to kill such a process, gives up, then kills its "partner" successfully leaving the former unkilled even though it could have killed it too, had it retried later.



If this case is true, another question would be, does kill <PID list> obey the order of PIDs in my list or do I have to use separate kill processes to control the order in which processes get killed?









share|improve this question











share|improve this question




share|improve this question










asked Feb 7 at 8:33









argle

331115




331115







  • 1




    What do you mean with "Some processes can't be killed before other processes"?
    – dr01
    Feb 7 at 8:56






  • 2




    I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
    – Giacomo Catenazzi
    Feb 7 at 9:50












  • 1




    What do you mean with "Some processes can't be killed before other processes"?
    – dr01
    Feb 7 at 8:56






  • 2




    I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
    – Giacomo Catenazzi
    Feb 7 at 9:50







1




1




What do you mean with "Some processes can't be killed before other processes"?
– dr01
Feb 7 at 8:56




What do you mean with "Some processes can't be killed before other processes"?
– dr01
Feb 7 at 8:56




2




2




I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
– Giacomo Catenazzi
Feb 7 at 9:50




I think he mean the case of daemon which span children processes. Killing children just make the daemon to create new children. Killing the parent now will (potentially) leave some new born children alive.
– Giacomo Catenazzi
Feb 7 at 9:50










3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










I doubt there's anything more than just sending the signal to each of the targets in turn. The POSIX definition for kill(1) is just that, so retrying seems it would be in violation of the specification:




The kill utility shall send a signal to the process or processes specified by each pid operand.



For each pid operand, the kill utility shall perform actions equivalent to the kill() function




Also, remember that not all signals cause processes to terminate, and some like SIGHUP (let alone SIGUSR1) may mean different things for different programs. There's no clear way for kill to know when to retry, but there surely exist programs that first send SIGTERM and later "retry" with SIGKILL.



Sending the signals in the order given would be the straightforward implementation, and that's what e.g. Bash's kill does:



$ strace -etrace=kill bash -c 'kill -0 33330 33339 33335 33332 33337' |& grep ^'kill('
kill(33330, SIG_0) = -1 ESRCH (No such process)
kill(33339, SIG_0) = -1 ESRCH (No such process)
kill(33335, SIG_0) = -1 ESRCH (No such process)
kill(33332, SIG_0) = -1 ESRCH (No such process)
kill(33337, SIG_0) = -1 ESRCH (No such process)





share|improve this answer



























    up vote
    0
    down vote













    kill <PID list> simply sends the specified signal to the specified list of processes. Then the behavior of your system depends whether that particular process ignores or not that particular signal. By default, kill sends a TERM signal.



    Assuming you're talking about SIGKILL here, this signal cannot be blocked or ignored. So kill -9 will kill the listed processes, unless for some reason the process is unresponsive (e.g. waiting for I/O on a blocked NFS).






    share|improve this answer






















    • Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
      – Kusalananda
      Feb 7 at 8:58


















    up vote
    0
    down vote













    We can answer that question by simply looking at kill.c.



    Basically we just:



    • list all processes with struct proc_processes ps = proc_open_processes();
      then we filter that list by pids or processes names and send


    • kill_verbose(&ctl) to every found process, which is just simple
      kill(ctl->pid, ctl->numsig)


    When process is killed with SIGKILL, it is terminated. From signal.h:



    terminate - kill the process, i.e. all threads in the group,
    similar to exit_group. The group leader (only) reports
    WIFSIGNALED status to its parent.


    So as you can see it is just simple "send message to process" command. Nothing fancy.






    share|improve this answer




















      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',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      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%2f422481%2fdoes-kill-pid-list-figure-out-the-correct-order-of-killing-or-does-it-do-pr%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      I doubt there's anything more than just sending the signal to each of the targets in turn. The POSIX definition for kill(1) is just that, so retrying seems it would be in violation of the specification:




      The kill utility shall send a signal to the process or processes specified by each pid operand.



      For each pid operand, the kill utility shall perform actions equivalent to the kill() function




      Also, remember that not all signals cause processes to terminate, and some like SIGHUP (let alone SIGUSR1) may mean different things for different programs. There's no clear way for kill to know when to retry, but there surely exist programs that first send SIGTERM and later "retry" with SIGKILL.



      Sending the signals in the order given would be the straightforward implementation, and that's what e.g. Bash's kill does:



      $ strace -etrace=kill bash -c 'kill -0 33330 33339 33335 33332 33337' |& grep ^'kill('
      kill(33330, SIG_0) = -1 ESRCH (No such process)
      kill(33339, SIG_0) = -1 ESRCH (No such process)
      kill(33335, SIG_0) = -1 ESRCH (No such process)
      kill(33332, SIG_0) = -1 ESRCH (No such process)
      kill(33337, SIG_0) = -1 ESRCH (No such process)





      share|improve this answer
























        up vote
        0
        down vote



        accepted










        I doubt there's anything more than just sending the signal to each of the targets in turn. The POSIX definition for kill(1) is just that, so retrying seems it would be in violation of the specification:




        The kill utility shall send a signal to the process or processes specified by each pid operand.



        For each pid operand, the kill utility shall perform actions equivalent to the kill() function




        Also, remember that not all signals cause processes to terminate, and some like SIGHUP (let alone SIGUSR1) may mean different things for different programs. There's no clear way for kill to know when to retry, but there surely exist programs that first send SIGTERM and later "retry" with SIGKILL.



        Sending the signals in the order given would be the straightforward implementation, and that's what e.g. Bash's kill does:



        $ strace -etrace=kill bash -c 'kill -0 33330 33339 33335 33332 33337' |& grep ^'kill('
        kill(33330, SIG_0) = -1 ESRCH (No such process)
        kill(33339, SIG_0) = -1 ESRCH (No such process)
        kill(33335, SIG_0) = -1 ESRCH (No such process)
        kill(33332, SIG_0) = -1 ESRCH (No such process)
        kill(33337, SIG_0) = -1 ESRCH (No such process)





        share|improve this answer






















          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          I doubt there's anything more than just sending the signal to each of the targets in turn. The POSIX definition for kill(1) is just that, so retrying seems it would be in violation of the specification:




          The kill utility shall send a signal to the process or processes specified by each pid operand.



          For each pid operand, the kill utility shall perform actions equivalent to the kill() function




          Also, remember that not all signals cause processes to terminate, and some like SIGHUP (let alone SIGUSR1) may mean different things for different programs. There's no clear way for kill to know when to retry, but there surely exist programs that first send SIGTERM and later "retry" with SIGKILL.



          Sending the signals in the order given would be the straightforward implementation, and that's what e.g. Bash's kill does:



          $ strace -etrace=kill bash -c 'kill -0 33330 33339 33335 33332 33337' |& grep ^'kill('
          kill(33330, SIG_0) = -1 ESRCH (No such process)
          kill(33339, SIG_0) = -1 ESRCH (No such process)
          kill(33335, SIG_0) = -1 ESRCH (No such process)
          kill(33332, SIG_0) = -1 ESRCH (No such process)
          kill(33337, SIG_0) = -1 ESRCH (No such process)





          share|improve this answer












          I doubt there's anything more than just sending the signal to each of the targets in turn. The POSIX definition for kill(1) is just that, so retrying seems it would be in violation of the specification:




          The kill utility shall send a signal to the process or processes specified by each pid operand.



          For each pid operand, the kill utility shall perform actions equivalent to the kill() function




          Also, remember that not all signals cause processes to terminate, and some like SIGHUP (let alone SIGUSR1) may mean different things for different programs. There's no clear way for kill to know when to retry, but there surely exist programs that first send SIGTERM and later "retry" with SIGKILL.



          Sending the signals in the order given would be the straightforward implementation, and that's what e.g. Bash's kill does:



          $ strace -etrace=kill bash -c 'kill -0 33330 33339 33335 33332 33337' |& grep ^'kill('
          kill(33330, SIG_0) = -1 ESRCH (No such process)
          kill(33339, SIG_0) = -1 ESRCH (No such process)
          kill(33335, SIG_0) = -1 ESRCH (No such process)
          kill(33332, SIG_0) = -1 ESRCH (No such process)
          kill(33337, SIG_0) = -1 ESRCH (No such process)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 7 at 10:27









          ilkkachu

          49.6k673137




          49.6k673137






















              up vote
              0
              down vote













              kill <PID list> simply sends the specified signal to the specified list of processes. Then the behavior of your system depends whether that particular process ignores or not that particular signal. By default, kill sends a TERM signal.



              Assuming you're talking about SIGKILL here, this signal cannot be blocked or ignored. So kill -9 will kill the listed processes, unless for some reason the process is unresponsive (e.g. waiting for I/O on a blocked NFS).






              share|improve this answer






















              • Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
                – Kusalananda
                Feb 7 at 8:58















              up vote
              0
              down vote













              kill <PID list> simply sends the specified signal to the specified list of processes. Then the behavior of your system depends whether that particular process ignores or not that particular signal. By default, kill sends a TERM signal.



              Assuming you're talking about SIGKILL here, this signal cannot be blocked or ignored. So kill -9 will kill the listed processes, unless for some reason the process is unresponsive (e.g. waiting for I/O on a blocked NFS).






              share|improve this answer






















              • Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
                – Kusalananda
                Feb 7 at 8:58













              up vote
              0
              down vote










              up vote
              0
              down vote









              kill <PID list> simply sends the specified signal to the specified list of processes. Then the behavior of your system depends whether that particular process ignores or not that particular signal. By default, kill sends a TERM signal.



              Assuming you're talking about SIGKILL here, this signal cannot be blocked or ignored. So kill -9 will kill the listed processes, unless for some reason the process is unresponsive (e.g. waiting for I/O on a blocked NFS).






              share|improve this answer














              kill <PID list> simply sends the specified signal to the specified list of processes. Then the behavior of your system depends whether that particular process ignores or not that particular signal. By default, kill sends a TERM signal.



              Assuming you're talking about SIGKILL here, this signal cannot be blocked or ignored. So kill -9 will kill the listed processes, unless for some reason the process is unresponsive (e.g. waiting for I/O on a blocked NFS).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Feb 7 at 8:58

























              answered Feb 7 at 8:54









              dr01

              15.3k114768




              15.3k114768











              • Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
                – Kusalananda
                Feb 7 at 8:58

















              • Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
                – Kusalananda
                Feb 7 at 8:58
















              Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
              – Kusalananda
              Feb 7 at 8:58





              Additionally, I can find no reference to the order in which the processes are signalled. But I'd be surprised if it was random rather than sequential in either direction.
              – Kusalananda
              Feb 7 at 8:58











              up vote
              0
              down vote













              We can answer that question by simply looking at kill.c.



              Basically we just:



              • list all processes with struct proc_processes ps = proc_open_processes();
                then we filter that list by pids or processes names and send


              • kill_verbose(&ctl) to every found process, which is just simple
                kill(ctl->pid, ctl->numsig)


              When process is killed with SIGKILL, it is terminated. From signal.h:



              terminate - kill the process, i.e. all threads in the group,
              similar to exit_group. The group leader (only) reports
              WIFSIGNALED status to its parent.


              So as you can see it is just simple "send message to process" command. Nothing fancy.






              share|improve this answer
























                up vote
                0
                down vote













                We can answer that question by simply looking at kill.c.



                Basically we just:



                • list all processes with struct proc_processes ps = proc_open_processes();
                  then we filter that list by pids or processes names and send


                • kill_verbose(&ctl) to every found process, which is just simple
                  kill(ctl->pid, ctl->numsig)


                When process is killed with SIGKILL, it is terminated. From signal.h:



                terminate - kill the process, i.e. all threads in the group,
                similar to exit_group. The group leader (only) reports
                WIFSIGNALED status to its parent.


                So as you can see it is just simple "send message to process" command. Nothing fancy.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  We can answer that question by simply looking at kill.c.



                  Basically we just:



                  • list all processes with struct proc_processes ps = proc_open_processes();
                    then we filter that list by pids or processes names and send


                  • kill_verbose(&ctl) to every found process, which is just simple
                    kill(ctl->pid, ctl->numsig)


                  When process is killed with SIGKILL, it is terminated. From signal.h:



                  terminate - kill the process, i.e. all threads in the group,
                  similar to exit_group. The group leader (only) reports
                  WIFSIGNALED status to its parent.


                  So as you can see it is just simple "send message to process" command. Nothing fancy.






                  share|improve this answer












                  We can answer that question by simply looking at kill.c.



                  Basically we just:



                  • list all processes with struct proc_processes ps = proc_open_processes();
                    then we filter that list by pids or processes names and send


                  • kill_verbose(&ctl) to every found process, which is just simple
                    kill(ctl->pid, ctl->numsig)


                  When process is killed with SIGKILL, it is terminated. From signal.h:



                  terminate - kill the process, i.e. all threads in the group,
                  similar to exit_group. The group leader (only) reports
                  WIFSIGNALED status to its parent.


                  So as you can see it is just simple "send message to process" command. Nothing fancy.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 7 at 10:39









                  Neurootic

                  212




                  212






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f422481%2fdoes-kill-pid-list-figure-out-the-correct-order-of-killing-or-does-it-do-pr%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay