Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I usually kill a process with killall.

killall markdoc

But I can't sure this command terminates the process gracefully. Does this command graceful termination? If it's 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

3 Answers 3

up vote 6 down vote accepted

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

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 \t\e[1;34m$target\e[0;0m\n"
  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

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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.