What does a program do when it's sent SIGKILL signal?











up vote
35
down vote

favorite
9












When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really.
So, what's happening during those minutes?










share|improve this question









New contributor




haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    35
    down vote

    favorite
    9












    When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really.
    So, what's happening during those minutes?










    share|improve this question









    New contributor




    haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      35
      down vote

      favorite
      9









      up vote
      35
      down vote

      favorite
      9






      9





      When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really.
      So, what's happening during those minutes?










      share|improve this question









      New contributor




      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really.
      So, what's happening during those minutes?







      kill






      share|improve this question









      New contributor




      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday









      Monty Harder

      22215




      22215






      New contributor




      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      haikun he

      17824




      17824




      New contributor




      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      haikun he is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          57
          down vote



          accepted










          The program actually never receives the SIGKILL signal, as SIGKILL is completely handled by the operating system/kernel.



          When SIGKILL for a specific process is sent, the kernel's scheduler immediately stops giving that process any more CPU time for running user-space code. If the process has any threads executing user-space code on other CPUs/cores at the time the scheduler makes this decision, those threads will be stopped too. (In single-core systems this used to be much simpler: if the only CPU core in the system was running the scheduler, it by definition wasn't running the process at the same time!)



          If the process/thread is executing kernel code (e.g. a system call, or an I/O operation associated with a memory-mapped file) at the time of SIGKILL, it gets a bit trickier: only some system calls are interruptible, so the kernel internally marks the process as being in a special "dying" state until the system calls or I/O operations are resolved. CPU time to resolve those will be scheduled as usual. Interruptible system calls or I/O operations will check if the process that called them is dying at any suitable stopping points, and will exit early in that case. Uninterruptible operations will run into completion, and will check for a "dying" state just before returning to user-space code.



          Once any in-process kernel routines are resolved, the process state is changed from "dying" to "dead" and the kernel begins cleaning it up, similar to when a program exits normally. Once the clean-up is complete, a greater-than-128 result code will be assigned (to indicate that the process was killed by a signal; see this answer for the messy details), and the process will transition into "zombie" state. The parent of the killed process will be notified with a SIGCHLD signal.



          As a result, the process itself will never get the chance to actually process the information that it has received a SIGKILL.



          When a process is in a "zombie" state it means the process is already dead, but its parent process has not yet acknowledged this by reading the exit code of the dead process using the wait(2) system call. Basically the only resource a zombie process is consuming any more is a slot in the process table that holds its PID, the exit code and some other "vital statistics" of the process at the time of its death.



          If the parent process dies before its children, the orphaned child processes are automatically adopted by PID #1, which has a special duty to keep calling wait(2) so that any orphaned processes won't stick around as zombies.



          If it takes several minutes for a zombie process to clear, it suggests that the parent process of the zombie is struggling or not doing its job properly.



          There is a tongue-in-cheek description on what to do in case of zombie problems in Unix-like operating systems: "You cannot do anything for the zombies themselves, as they are already dead. Instead, kill the evil zombie master!" (i.e. the parent process of the troublesome zombies)






          share|improve this answer



















          • 5




            What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
            – gidds
            yesterday






          • 9




            @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
            – zwol
            yesterday






          • 6




            It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
            – kasperd
            yesterday






          • 4




            @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
            – kasperd
            yesterday






          • 2




            @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
            – kasperd
            yesterday











          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: 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
          });


          }
          });






          haikun he is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485644%2fwhat-does-a-program-do-when-its-sent-sigkill-signal%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
          57
          down vote



          accepted










          The program actually never receives the SIGKILL signal, as SIGKILL is completely handled by the operating system/kernel.



          When SIGKILL for a specific process is sent, the kernel's scheduler immediately stops giving that process any more CPU time for running user-space code. If the process has any threads executing user-space code on other CPUs/cores at the time the scheduler makes this decision, those threads will be stopped too. (In single-core systems this used to be much simpler: if the only CPU core in the system was running the scheduler, it by definition wasn't running the process at the same time!)



          If the process/thread is executing kernel code (e.g. a system call, or an I/O operation associated with a memory-mapped file) at the time of SIGKILL, it gets a bit trickier: only some system calls are interruptible, so the kernel internally marks the process as being in a special "dying" state until the system calls or I/O operations are resolved. CPU time to resolve those will be scheduled as usual. Interruptible system calls or I/O operations will check if the process that called them is dying at any suitable stopping points, and will exit early in that case. Uninterruptible operations will run into completion, and will check for a "dying" state just before returning to user-space code.



          Once any in-process kernel routines are resolved, the process state is changed from "dying" to "dead" and the kernel begins cleaning it up, similar to when a program exits normally. Once the clean-up is complete, a greater-than-128 result code will be assigned (to indicate that the process was killed by a signal; see this answer for the messy details), and the process will transition into "zombie" state. The parent of the killed process will be notified with a SIGCHLD signal.



          As a result, the process itself will never get the chance to actually process the information that it has received a SIGKILL.



          When a process is in a "zombie" state it means the process is already dead, but its parent process has not yet acknowledged this by reading the exit code of the dead process using the wait(2) system call. Basically the only resource a zombie process is consuming any more is a slot in the process table that holds its PID, the exit code and some other "vital statistics" of the process at the time of its death.



          If the parent process dies before its children, the orphaned child processes are automatically adopted by PID #1, which has a special duty to keep calling wait(2) so that any orphaned processes won't stick around as zombies.



          If it takes several minutes for a zombie process to clear, it suggests that the parent process of the zombie is struggling or not doing its job properly.



          There is a tongue-in-cheek description on what to do in case of zombie problems in Unix-like operating systems: "You cannot do anything for the zombies themselves, as they are already dead. Instead, kill the evil zombie master!" (i.e. the parent process of the troublesome zombies)






          share|improve this answer



















          • 5




            What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
            – gidds
            yesterday






          • 9




            @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
            – zwol
            yesterday






          • 6




            It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
            – kasperd
            yesterday






          • 4




            @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
            – kasperd
            yesterday






          • 2




            @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
            – kasperd
            yesterday















          up vote
          57
          down vote



          accepted










          The program actually never receives the SIGKILL signal, as SIGKILL is completely handled by the operating system/kernel.



          When SIGKILL for a specific process is sent, the kernel's scheduler immediately stops giving that process any more CPU time for running user-space code. If the process has any threads executing user-space code on other CPUs/cores at the time the scheduler makes this decision, those threads will be stopped too. (In single-core systems this used to be much simpler: if the only CPU core in the system was running the scheduler, it by definition wasn't running the process at the same time!)



          If the process/thread is executing kernel code (e.g. a system call, or an I/O operation associated with a memory-mapped file) at the time of SIGKILL, it gets a bit trickier: only some system calls are interruptible, so the kernel internally marks the process as being in a special "dying" state until the system calls or I/O operations are resolved. CPU time to resolve those will be scheduled as usual. Interruptible system calls or I/O operations will check if the process that called them is dying at any suitable stopping points, and will exit early in that case. Uninterruptible operations will run into completion, and will check for a "dying" state just before returning to user-space code.



          Once any in-process kernel routines are resolved, the process state is changed from "dying" to "dead" and the kernel begins cleaning it up, similar to when a program exits normally. Once the clean-up is complete, a greater-than-128 result code will be assigned (to indicate that the process was killed by a signal; see this answer for the messy details), and the process will transition into "zombie" state. The parent of the killed process will be notified with a SIGCHLD signal.



          As a result, the process itself will never get the chance to actually process the information that it has received a SIGKILL.



          When a process is in a "zombie" state it means the process is already dead, but its parent process has not yet acknowledged this by reading the exit code of the dead process using the wait(2) system call. Basically the only resource a zombie process is consuming any more is a slot in the process table that holds its PID, the exit code and some other "vital statistics" of the process at the time of its death.



          If the parent process dies before its children, the orphaned child processes are automatically adopted by PID #1, which has a special duty to keep calling wait(2) so that any orphaned processes won't stick around as zombies.



          If it takes several minutes for a zombie process to clear, it suggests that the parent process of the zombie is struggling or not doing its job properly.



          There is a tongue-in-cheek description on what to do in case of zombie problems in Unix-like operating systems: "You cannot do anything for the zombies themselves, as they are already dead. Instead, kill the evil zombie master!" (i.e. the parent process of the troublesome zombies)






          share|improve this answer



















          • 5




            What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
            – gidds
            yesterday






          • 9




            @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
            – zwol
            yesterday






          • 6




            It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
            – kasperd
            yesterday






          • 4




            @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
            – kasperd
            yesterday






          • 2




            @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
            – kasperd
            yesterday













          up vote
          57
          down vote



          accepted







          up vote
          57
          down vote



          accepted






          The program actually never receives the SIGKILL signal, as SIGKILL is completely handled by the operating system/kernel.



          When SIGKILL for a specific process is sent, the kernel's scheduler immediately stops giving that process any more CPU time for running user-space code. If the process has any threads executing user-space code on other CPUs/cores at the time the scheduler makes this decision, those threads will be stopped too. (In single-core systems this used to be much simpler: if the only CPU core in the system was running the scheduler, it by definition wasn't running the process at the same time!)



          If the process/thread is executing kernel code (e.g. a system call, or an I/O operation associated with a memory-mapped file) at the time of SIGKILL, it gets a bit trickier: only some system calls are interruptible, so the kernel internally marks the process as being in a special "dying" state until the system calls or I/O operations are resolved. CPU time to resolve those will be scheduled as usual. Interruptible system calls or I/O operations will check if the process that called them is dying at any suitable stopping points, and will exit early in that case. Uninterruptible operations will run into completion, and will check for a "dying" state just before returning to user-space code.



          Once any in-process kernel routines are resolved, the process state is changed from "dying" to "dead" and the kernel begins cleaning it up, similar to when a program exits normally. Once the clean-up is complete, a greater-than-128 result code will be assigned (to indicate that the process was killed by a signal; see this answer for the messy details), and the process will transition into "zombie" state. The parent of the killed process will be notified with a SIGCHLD signal.



          As a result, the process itself will never get the chance to actually process the information that it has received a SIGKILL.



          When a process is in a "zombie" state it means the process is already dead, but its parent process has not yet acknowledged this by reading the exit code of the dead process using the wait(2) system call. Basically the only resource a zombie process is consuming any more is a slot in the process table that holds its PID, the exit code and some other "vital statistics" of the process at the time of its death.



          If the parent process dies before its children, the orphaned child processes are automatically adopted by PID #1, which has a special duty to keep calling wait(2) so that any orphaned processes won't stick around as zombies.



          If it takes several minutes for a zombie process to clear, it suggests that the parent process of the zombie is struggling or not doing its job properly.



          There is a tongue-in-cheek description on what to do in case of zombie problems in Unix-like operating systems: "You cannot do anything for the zombies themselves, as they are already dead. Instead, kill the evil zombie master!" (i.e. the parent process of the troublesome zombies)






          share|improve this answer














          The program actually never receives the SIGKILL signal, as SIGKILL is completely handled by the operating system/kernel.



          When SIGKILL for a specific process is sent, the kernel's scheduler immediately stops giving that process any more CPU time for running user-space code. If the process has any threads executing user-space code on other CPUs/cores at the time the scheduler makes this decision, those threads will be stopped too. (In single-core systems this used to be much simpler: if the only CPU core in the system was running the scheduler, it by definition wasn't running the process at the same time!)



          If the process/thread is executing kernel code (e.g. a system call, or an I/O operation associated with a memory-mapped file) at the time of SIGKILL, it gets a bit trickier: only some system calls are interruptible, so the kernel internally marks the process as being in a special "dying" state until the system calls or I/O operations are resolved. CPU time to resolve those will be scheduled as usual. Interruptible system calls or I/O operations will check if the process that called them is dying at any suitable stopping points, and will exit early in that case. Uninterruptible operations will run into completion, and will check for a "dying" state just before returning to user-space code.



          Once any in-process kernel routines are resolved, the process state is changed from "dying" to "dead" and the kernel begins cleaning it up, similar to when a program exits normally. Once the clean-up is complete, a greater-than-128 result code will be assigned (to indicate that the process was killed by a signal; see this answer for the messy details), and the process will transition into "zombie" state. The parent of the killed process will be notified with a SIGCHLD signal.



          As a result, the process itself will never get the chance to actually process the information that it has received a SIGKILL.



          When a process is in a "zombie" state it means the process is already dead, but its parent process has not yet acknowledged this by reading the exit code of the dead process using the wait(2) system call. Basically the only resource a zombie process is consuming any more is a slot in the process table that holds its PID, the exit code and some other "vital statistics" of the process at the time of its death.



          If the parent process dies before its children, the orphaned child processes are automatically adopted by PID #1, which has a special duty to keep calling wait(2) so that any orphaned processes won't stick around as zombies.



          If it takes several minutes for a zombie process to clear, it suggests that the parent process of the zombie is struggling or not doing its job properly.



          There is a tongue-in-cheek description on what to do in case of zombie problems in Unix-like operating systems: "You cannot do anything for the zombies themselves, as they are already dead. Instead, kill the evil zombie master!" (i.e. the parent process of the troublesome zombies)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 19 hours ago

























          answered yesterday









          telcoM

          15k12143




          15k12143








          • 5




            What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
            – gidds
            yesterday






          • 9




            @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
            – zwol
            yesterday






          • 6




            It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
            – kasperd
            yesterday






          • 4




            @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
            – kasperd
            yesterday






          • 2




            @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
            – kasperd
            yesterday














          • 5




            What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
            – gidds
            yesterday






          • 9




            @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
            – zwol
            yesterday






          • 6




            It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
            – kasperd
            yesterday






          • 4




            @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
            – kasperd
            yesterday






          • 2




            @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
            – kasperd
            yesterday








          5




          5




          What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
          – gidds
          yesterday




          What happens if the process is in a kernel call (e.g. doing I/O) when SIGKILL is sent?
          – gidds
          yesterday




          9




          9




          @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
          – zwol
          yesterday




          @gidds Either the I/O will be cancelled in order to execute the SIGKILL, or the SIGKILL will be delayed until the I/O completes. This is the difference between 'S' and 'D' sleep states in ps: 'S' is for I/O waits that the kernel can cancel in order to deliver a signal, and 'D' for those it can't.
          – zwol
          yesterday




          6




          6




          It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
          – kasperd
          yesterday




          It's not entirely accurate to say the schedule immediately stops giving the process CPU time. The kernel side of the signal handling is still executed by that process, but the process will only be executing kernel code so you are right when you say the program never receives the signal. The process will be executing kernel code responsible for most of the cleanup of resources (open files, virtual memory, etc.) The last steps of this cleanup code is to change the process state to zombie and invoke the scheduler. Then it will never be scheduled again.
          – kasperd
          yesterday




          4




          4




          @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
          – kasperd
          yesterday




          @gidds There are at least four different states that process can be in. It can be running kernel code at the moment or it can be sleeping in one of three different sleep states. The sleep states can either be interruptible, non-interruptible, or non-interruptible except for deadly signals. If it is in non-interruptible sleep it will be left sleeping for as long as it needs and only once it wakes up will it have a chance to die. If it was in one of the other two sleep states it will be woken up immediately and scheduled as soon as there is a CPU available for it.
          – kasperd
          yesterday




          2




          2




          @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
          – kasperd
          yesterday




          @gidds What happens next depends on the kernel code it was running. Regardless of whether it was already running or first had to be woken up and then could start running the kernel code it was in at the time will be allowed to continue. And that kernel code is responsible for noticing that the process has been told to die and act accordingly. Most of the time the proper way to deal with that in kernel code is to just return an error from whatever function it was executing. Once the kernel call stack has been unwound the signal handling code can take over just before returning to user mode.
          – kasperd
          yesterday










          haikun he is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          haikun he is a new contributor. Be nice, and check out our Code of Conduct.













          haikun he is a new contributor. Be nice, and check out our Code of Conduct.












          haikun he is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f485644%2fwhat-does-a-program-do-when-its-sent-sigkill-signal%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

          Ellipse (mathématiques)

          Quarter-circle Tiles

          Mont Emei