Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I run a daemon which cannot be restarted via init.d or service command.

Is there a way to restart a process just by passing a process id to some command?

share|improve this question
Can you clarify what you mean? You want to restart a running process by passing the PID of that process? – Roger Light Dec 1 '10 at 13:18
yes, exactly. instead of killing a process and retyping a command with lots of params, i'd like to restart a process just by passing it's PID (or is there something better for doing it then passing a PID?) – neziric Dec 1 '10 at 13:24
Ok, so is there a reason why it can't be restarted with init.d/service? If the appropriate script doesn't exist it might be better to write it. – Roger Light Dec 1 '10 at 14:05
i tried to avoid that, but for this program it seems i had to do it. thanks everyone – neziric Dec 1 '10 at 14:44
up vote 4 down vote accepted

Killing or Reconfiguring a Daemon without Restarting

kill -HUP 1721

Restarts the process 1721 by sending the hangup signal.

killall -HUP inetd

Causes the daemon to reload its config file by sending the hangup signal.

killall -1 inetd 

Restarts inetd by sending signal number 1 which is the hangup signal.

The difference between this example and the previous one is the signal is called by name here rather than number.


share|improve this answer
Certainly worth checking, but you can't depend on this behaviour for any given program. – Roger Light Dec 1 '10 at 14:00
thanks a lot for the link. it's what i've been looking for. oh, i've forgot to mention that i can reload a process like this, but it only works for programs i installed via apt (like apache, mysql). the one i compiled is not affected – neziric Dec 1 '10 at 14:01
It only works for those applications which explicitly setup a SIGHUP signal handler. It is not a general solution to restart processes. – João Pinto Dec 1 '10 at 15:25

you can use the following command

CMD=`cat /proc/1234/cmdline |sed 's/\x0/ /g'` && kill 1234 && `$CMD` &

where 1234 is the process id.

What this line does is that first it copies the command line that was used to run that process into a variable, then it kills that process and restarts it using the stored command line.

Update: above command line has been updated

share|improve this answer
I strongly doubt you mean "&" here. Regardless, that doesn't work. – Roger Light Dec 1 '10 at 13:57
Can u plz try now. cmdline in /proc has spaces replaced with null charcters. i have added a command to replace them back. also use of '&' between commands was a typo which i have corrected – binW Dec 2 '10 at 6:41

Your Answer


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.