How to kill a daemon with its name gracefully? The 2019 Stack Overflow Developer Survey...

Loose spokes after only a few rides

Can each chord in a progression create its own key?

Why did Peik Lin say, "I'm not an animal"?

Homework question about an engine pulling a train

First use of “packing” as in carrying a gun

Single author papers against my advisor's will?

Deal with toxic manager when you can't quit

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Why not take a picture of a closer black hole?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

how can a perfect fourth interval be considered either consonant or dissonant?

Example of compact Riemannian manifold with only one geodesic.

What aspect of planet Earth must be changed to prevent the industrial revolution?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

Could an empire control the whole planet with today's comunication methods?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Drawing arrows from one table cell reference to another

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What is the padding with red substance inside of steak packaging?

60's-70's movie: home appliances revolting against the owners

How to determine omitted units in a publication

Student Loan from years ago pops up and is taking my salary

What force causes entropy to increase?

Do I have Disadvantage attacking with an off-hand weapon?



How to kill a daemon with its name gracefully?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsHow to kill both process and subprocess?How long has GNU kill(1) accepted a name argument?How can I kill the top CPU/IO process quickly?pkill can't kill processes with parent process id 1How to kill the (last - 1) PID with bashWhy does killall command kill only one instance of the process?How to kill all process with given name?PID of a bash process not captured by $!3 different apps with the same file name in different locations, how to kill one by its full name?Does tmux kill-server shut down running applications gracefully?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







14















I usually kill a process with killall.



killall markdoc


But I am not sure if this command terminates the process gracefully.
Does this command achieve graceful termination? If it does not, how can I kill a process with its name gracefully?










share|improve this question

























  • Does your distribution has start-stop-daemon?

    – manatwork
    Jan 4 '12 at 9:52













  • I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

    – Eonil
    Jan 4 '12 at 10:33











  • It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

    – manatwork
    Jan 4 '12 at 12:34




















14















I usually kill a process with killall.



killall markdoc


But I am not sure if this command terminates the process gracefully.
Does this command achieve graceful termination? If it does not, how can I kill a process with its name gracefully?










share|improve this question

























  • Does your distribution has start-stop-daemon?

    – manatwork
    Jan 4 '12 at 9:52













  • I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

    – Eonil
    Jan 4 '12 at 10:33











  • It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

    – manatwork
    Jan 4 '12 at 12:34
















14












14








14


6






I usually kill a process with killall.



killall markdoc


But I am not sure if this command terminates the process gracefully.
Does this command achieve graceful termination? If it does not, how can I kill a process with its name gracefully?










share|improve this question
















I usually kill a process with killall.



killall markdoc


But I am not sure if this command terminates the process gracefully.
Does this command achieve graceful termination? If it does not, how can I kill a process with its name gracefully?







process kill






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 16 '14 at 4:46









crisron

309315




309315










asked Jan 4 '12 at 6:00









EonilEonil

1,58772229




1,58772229













  • Does your distribution has start-stop-daemon?

    – manatwork
    Jan 4 '12 at 9:52













  • I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

    – Eonil
    Jan 4 '12 at 10:33











  • It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

    – manatwork
    Jan 4 '12 at 12:34





















  • Does your distribution has start-stop-daemon?

    – manatwork
    Jan 4 '12 at 9:52













  • I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

    – Eonil
    Jan 4 '12 at 10:33











  • It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

    – manatwork
    Jan 4 '12 at 12:34



















Does your distribution has start-stop-daemon?

– manatwork
Jan 4 '12 at 9:52







Does your distribution has start-stop-daemon?

– manatwork
Jan 4 '12 at 9:52















I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

– Eonil
Jan 4 '12 at 10:33





I'm using Ubuntu 10.04 LTS server x64. What's that daemon?

– Eonil
Jan 4 '12 at 10:33













It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

– manatwork
Jan 4 '12 at 12:34







It is a generic tool for starting/stopping daemons and managing related information, like pid files. It is present in Ubuntu, see its man page.

– manatwork
Jan 4 '12 at 12:34












3 Answers
3






active

oldest

votes


















17














Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.



For a daemon there are specific means to stop it, for example in Debian you have



    service daemon-name stop


or



    /etc/init.d/daemon-name stop


Similar syntaxes exist for other initscript standards used in other distributions/OS.



To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall or pkill, given that they use by default the SIGTERM (15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.



If that do not work, you can try SIGINT (2), then SIGHUP (1), and as a last resort SIGKILL (9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.



Both pkill and killall accept a signal parameter in the form -NAME, as in



pkill -INT process-name





share|improve this answer


























  • Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

    – Eonil
    Jan 4 '12 at 9:01













  • killall is the killer!

    – xdevs23
    May 9 '16 at 16:04



















2














On BSD-like and other distros, you will often have scripts in /etc/rc.d/ that typically manages starting, restarting and stopping daemons in your system. To stop a daemon you would either call the scripts with the absolute path e.g.:



# /etc/rc.d/acpid stop


or use the command:



# rc.d stop acpid


I highly recommend to try out this script for showing your systems started and stopped daemons:



#!/bin/bash

chk_status(){
target=$1
if [[ $target != "functions" && $target != "functions.d" ]]
then
if [[ -f "/var/run/daemons/$target" ]]
then
stat="e[1;32m[RUNNING]"
else
stat="e[1;31m[STOPPED]"
fi

printf "$stat te[1;34m$targete[0;0mn"
fi
}

daemons=($(for daemon in /etc/rc.d/*; do echo "${daemon#/etc/rc.d/}"; done))

if [[ $1 != "" ]]
then
chk_status $1
else
for d in "${daemons[@]}"; do
chk_status $d
done | sort
fi





share|improve this answer































    0














    Check for killproc function available in /etc/init.d/functions script, source the file and use the function. Or use pgrep and pkill utilities to check whether they are working intendedly and then use them. Example: pkill -SIGTERM mysqld would send the TERM kill signal to have mysqld perform a safe shutdown and flush the databases onto the disk, before getting killed.






    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',
      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%2f28260%2fhow-to-kill-a-daemon-with-its-name-gracefully%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      17














      Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.



      For a daemon there are specific means to stop it, for example in Debian you have



          service daemon-name stop


      or



          /etc/init.d/daemon-name stop


      Similar syntaxes exist for other initscript standards used in other distributions/OS.



      To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall or pkill, given that they use by default the SIGTERM (15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.



      If that do not work, you can try SIGINT (2), then SIGHUP (1), and as a last resort SIGKILL (9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.



      Both pkill and killall accept a signal parameter in the form -NAME, as in



      pkill -INT process-name





      share|improve this answer


























      • Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

        – Eonil
        Jan 4 '12 at 9:01













      • killall is the killer!

        – xdevs23
        May 9 '16 at 16:04
















      17














      Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.



      For a daemon there are specific means to stop it, for example in Debian you have



          service daemon-name stop


      or



          /etc/init.d/daemon-name stop


      Similar syntaxes exist for other initscript standards used in other distributions/OS.



      To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall or pkill, given that they use by default the SIGTERM (15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.



      If that do not work, you can try SIGINT (2), then SIGHUP (1), and as a last resort SIGKILL (9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.



      Both pkill and killall accept a signal parameter in the form -NAME, as in



      pkill -INT process-name





      share|improve this answer


























      • Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

        – Eonil
        Jan 4 '12 at 9:01













      • killall is the killer!

        – xdevs23
        May 9 '16 at 16:04














      17












      17








      17







      Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.



      For a daemon there are specific means to stop it, for example in Debian you have



          service daemon-name stop


      or



          /etc/init.d/daemon-name stop


      Similar syntaxes exist for other initscript standards used in other distributions/OS.



      To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall or pkill, given that they use by default the SIGTERM (15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.



      If that do not work, you can try SIGINT (2), then SIGHUP (1), and as a last resort SIGKILL (9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.



      Both pkill and killall accept a signal parameter in the form -NAME, as in



      pkill -INT process-name





      share|improve this answer















      Your question is not clear, you talk about a daemon in the title, but in the body only talk about a generic process.



      For a daemon there are specific means to stop it, for example in Debian you have



          service daemon-name stop


      or



          /etc/init.d/daemon-name stop


      Similar syntaxes exist for other initscript standards used in other distributions/OS.



      To kill a non-daemon process, supposing it is in some way out of control, you can safely use killall or pkill, given that they use by default the SIGTERM (15) signal, and any decently written application should catch and gracefully exit on receiving this signal. Take into account that these utilities could kill more that one process, if there are many with the same name.



      If that do not work, you can try SIGINT (2), then SIGHUP (1), and as a last resort SIGKILL (9). This last signal cannot be catched by the application, so that it cannot perform any clean-up. For this reason it should be avoided every time you can.



      Both pkill and killall accept a signal parameter in the form -NAME, as in



      pkill -INT process-name






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 4 '12 at 7:21

























      answered Jan 4 '12 at 7:11









      enzotibenzotib

      34.7k810495




      34.7k810495













      • Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

        – Eonil
        Jan 4 '12 at 9:01













      • killall is the killer!

        – xdevs23
        May 9 '16 at 16:04



















      • Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

        – Eonil
        Jan 4 '12 at 9:01













      • killall is the killer!

        – xdevs23
        May 9 '16 at 16:04

















      Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

      – Eonil
      Jan 4 '12 at 9:01







      Thank you. Actually my original question was about markdoc serve & and svnserve -d. I think it's a kind of daemon, but nothing was certain to me :)

      – Eonil
      Jan 4 '12 at 9:01















      killall is the killer!

      – xdevs23
      May 9 '16 at 16:04





      killall is the killer!

      – xdevs23
      May 9 '16 at 16:04













      2














      On BSD-like and other distros, you will often have scripts in /etc/rc.d/ that typically manages starting, restarting and stopping daemons in your system. To stop a daemon you would either call the scripts with the absolute path e.g.:



      # /etc/rc.d/acpid stop


      or use the command:



      # rc.d stop acpid


      I highly recommend to try out this script for showing your systems started and stopped daemons:



      #!/bin/bash

      chk_status(){
      target=$1
      if [[ $target != "functions" && $target != "functions.d" ]]
      then
      if [[ -f "/var/run/daemons/$target" ]]
      then
      stat="e[1;32m[RUNNING]"
      else
      stat="e[1;31m[STOPPED]"
      fi

      printf "$stat te[1;34m$targete[0;0mn"
      fi
      }

      daemons=($(for daemon in /etc/rc.d/*; do echo "${daemon#/etc/rc.d/}"; done))

      if [[ $1 != "" ]]
      then
      chk_status $1
      else
      for d in "${daemons[@]}"; do
      chk_status $d
      done | sort
      fi





      share|improve this answer




























        2














        On BSD-like and other distros, you will often have scripts in /etc/rc.d/ that typically manages starting, restarting and stopping daemons in your system. To stop a daemon you would either call the scripts with the absolute path e.g.:



        # /etc/rc.d/acpid stop


        or use the command:



        # rc.d stop acpid


        I highly recommend to try out this script for showing your systems started and stopped daemons:



        #!/bin/bash

        chk_status(){
        target=$1
        if [[ $target != "functions" && $target != "functions.d" ]]
        then
        if [[ -f "/var/run/daemons/$target" ]]
        then
        stat="e[1;32m[RUNNING]"
        else
        stat="e[1;31m[STOPPED]"
        fi

        printf "$stat te[1;34m$targete[0;0mn"
        fi
        }

        daemons=($(for daemon in /etc/rc.d/*; do echo "${daemon#/etc/rc.d/}"; done))

        if [[ $1 != "" ]]
        then
        chk_status $1
        else
        for d in "${daemons[@]}"; do
        chk_status $d
        done | sort
        fi





        share|improve this answer


























          2












          2








          2







          On BSD-like and other distros, you will often have scripts in /etc/rc.d/ that typically manages starting, restarting and stopping daemons in your system. To stop a daemon you would either call the scripts with the absolute path e.g.:



          # /etc/rc.d/acpid stop


          or use the command:



          # rc.d stop acpid


          I highly recommend to try out this script for showing your systems started and stopped daemons:



          #!/bin/bash

          chk_status(){
          target=$1
          if [[ $target != "functions" && $target != "functions.d" ]]
          then
          if [[ -f "/var/run/daemons/$target" ]]
          then
          stat="e[1;32m[RUNNING]"
          else
          stat="e[1;31m[STOPPED]"
          fi

          printf "$stat te[1;34m$targete[0;0mn"
          fi
          }

          daemons=($(for daemon in /etc/rc.d/*; do echo "${daemon#/etc/rc.d/}"; done))

          if [[ $1 != "" ]]
          then
          chk_status $1
          else
          for d in "${daemons[@]}"; do
          chk_status $d
          done | sort
          fi





          share|improve this answer













          On BSD-like and other distros, you will often have scripts in /etc/rc.d/ that typically manages starting, restarting and stopping daemons in your system. To stop a daemon you would either call the scripts with the absolute path e.g.:



          # /etc/rc.d/acpid stop


          or use the command:



          # rc.d stop acpid


          I highly recommend to try out this script for showing your systems started and stopped daemons:



          #!/bin/bash

          chk_status(){
          target=$1
          if [[ $target != "functions" && $target != "functions.d" ]]
          then
          if [[ -f "/var/run/daemons/$target" ]]
          then
          stat="e[1;32m[RUNNING]"
          else
          stat="e[1;31m[STOPPED]"
          fi

          printf "$stat te[1;34m$targete[0;0mn"
          fi
          }

          daemons=($(for daemon in /etc/rc.d/*; do echo "${daemon#/etc/rc.d/}"; done))

          if [[ $1 != "" ]]
          then
          chk_status $1
          else
          for d in "${daemons[@]}"; do
          chk_status $d
          done | sort
          fi






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 4 '12 at 8:01







          user13742






























              0














              Check for killproc function available in /etc/init.d/functions script, source the file and use the function. Or use pgrep and pkill utilities to check whether they are working intendedly and then use them. Example: pkill -SIGTERM mysqld would send the TERM kill signal to have mysqld perform a safe shutdown and flush the databases onto the disk, before getting killed.






              share|improve this answer




























                0














                Check for killproc function available in /etc/init.d/functions script, source the file and use the function. Or use pgrep and pkill utilities to check whether they are working intendedly and then use them. Example: pkill -SIGTERM mysqld would send the TERM kill signal to have mysqld perform a safe shutdown and flush the databases onto the disk, before getting killed.






                share|improve this answer


























                  0












                  0








                  0







                  Check for killproc function available in /etc/init.d/functions script, source the file and use the function. Or use pgrep and pkill utilities to check whether they are working intendedly and then use them. Example: pkill -SIGTERM mysqld would send the TERM kill signal to have mysqld perform a safe shutdown and flush the databases onto the disk, before getting killed.






                  share|improve this answer













                  Check for killproc function available in /etc/init.d/functions script, source the file and use the function. Or use pgrep and pkill utilities to check whether they are working intendedly and then use them. Example: pkill -SIGTERM mysqld would send the TERM kill signal to have mysqld perform a safe shutdown and flush the databases onto the disk, before getting killed.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 4 '12 at 6:14









                  Nikhil MulleyNikhil Mulley

                  6,4472245




                  6,4472245






























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f28260%2fhow-to-kill-a-daemon-with-its-name-gracefully%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

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m