Take the 2-minute tour ×

I have a process that other processes are trying to kill and if they manage to do it, how can I make sure the process will run again?

share|improve this question
Have you tried necromancy? –  FrustratedWithFormsDesigner May 21 '10 at 14:01
CoreWars! –  Marcelo Cantos May 21 '10 at 14:01
@Marcelo Cantos: That's awesome! I've gotta check that out later. –  FrustratedWithFormsDesigner May 21 '10 at 14:06
add comment

5 Answers

Check out inittab. Look for respawn :)

The process will be restarted whenever it terminates

Here is an example from my own inittab:


c1 is an id (is has to be unique), 2,3,4,5 are the runlevels to which this applies, respawn states what I have said earlier and the rest is a command. There you can simply add your command and it should work well.

share|improve this answer
Interesting. I hadn't thought of that, I usually only think of that for start-up settings. I guess this could work for processes started manually by the user? For Windows, I guess he'd have to write his process as a Windows process that automatically restarts (I think that's possible)... –  FrustratedWithFormsDesigner May 21 '10 at 14:06
I too would be interested for a way of doing that on Windows. EDIT: I found this: publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/… but haven't tested it. –  nc3b May 21 '10 at 14:10
I think that assumes he's running a WebSphere server, but he didn't even say that this was a server process or not. –  FrustratedWithFormsDesigner May 21 '10 at 14:27
add comment

You can respawn from inittab, but you have little control of when and how the process should be restarted--you have to edit the inittab to stop respawning. Also, inittab respawning can't do anything about locked processes and processes gone wild that are consuming massive CPU or RAM resources. You will also have no notice that your process is restarting every two seconds.

You can use a process monitoring daemon to get extra capabilities and flexibility. Monitoring daemons allow you to add arbitrarily complex behaviors to your process control. Of course, if you go too far in your demands, you may wind up having to write your own daemon.

It's better to use an existing solution that meets your needs.

I have had good results with Monit. The configuration language is quite powerful and you can do fairly complex things if you need to. You can also enable a web interface that allows you to stop, start and disable processes remotely. Check out the presentation for an overview.

share|improve this answer
add comment

Signal handling differs between the signals. Most signals reach the target process where a signal handler can take care of it e.g. SIGTERM which is what kill normally sends. If kill -sigkill (or kill -9, they are equivalent) is used the signal never reaches the process; the process is killed as soon as it can in a way that is safe for the OS (if it is busy in a system call, it will be killed as soon as the system call is finished, as a kill of a thread running in kernel mode could possibly chrash the OS if locks are not released etc).

So there is no way at all for a process to block or recover from a SIGKILL, regardless of programming language.

share|improve this answer
add comment

Some Linux versions (like Ubuntu) prefer /etc/event.d instead of inittab. It's a similar concept, but different implementation.

share|improve this answer
add comment

You could always pull a Robin Hood/Friar Tuck thing, but these days you can kill both processes at the same time.

share|improve this answer
add comment

Your Answer


