tags:

views:

88

answers:

6

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?

A: 

you can't do this

chburd
Didn't you see the `perl` tag? ;-)
mobrule
@mobrule: Hmm maybe CPAN has a RaiseTheDead module.
FrustratedWithFormsDesigner
@Frustrated, Check out [Acme::EmbalmingFluid::WorchestershireSauce](http://en.wikipedia.org/wiki/Pinkeye_%28South_Park%29)
daotoad
@daotoad: Ohhh yeah! That's a classic! :)
FrustratedWithFormsDesigner
+4  A: 

Check out inittab. Look for respawn :)

The process will be restarted whenever it terminates

Here is an example from my own inittab:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux

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.

nc3b
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
I too would be interested for a way of doing that on Windows. EDIT: I found this: http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/trun_processrestart.html but haven't tested it.
nc3b
@nc3b: 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
+2  A: 

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.

Anders Abel
+2  A: 

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

Paul Tomblin
+2  A: 

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.

daotoad
A: 

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

Chas. Owens