Here is a neat trick. If you want to start a program that always respawns if it gets killed, just put it in /etc/inittab. The init process will respawn the program. That's what it's for.

Here's an example. Let's say you want /bin/unkillable to always run. Put this in /etc/inittab:


Then run init q to make init re-read the inittab file. Now whenever /bin/unkillable gets killed, init will respawn it.

The init process uses this same trick to spawn terminals (otherwise if the terminals died and no one respawned them, no one would be able to log in from the physical terminals). This approach is also very useful if you absolutely must have some programs running. You don't even need complicated tools such as daemontools or supervisor to respawn programs. In most cases this trick is enough.

More information about init and /etc/inittab can be found in man init and man inittab. Until next time.

* by unkillable I mean one that respawns when you kill it.


February 01, 2014, 01:00

Nice trick. On Systemd based systems, you can correspondingly use "Restart" configuration option. ( I think that will do the same.

December 21, 2014, 03:37

oh fuck you with your systemd zealotry

you Permalink
July 01, 2015, 01:16

oh fuck you with your system init V zealotry

Justin Permalink
February 02, 2014, 16:47

on every Linux system I've seen that still uses /etc/inittab, init will delay respawning processes that exit too soon. Since init was largely used for stuff like running getty processes, it's a feature. With modern software, there's usually the expectation that you will start it as a privileged user, then it will drop privs, fork, and detach. Pass that to init and you'll get a respawn flurry-- the program must not detach from the calling process.

Doing what you describe has never been a popular way of running application code, as restart loops don't address the fact that your software shouldn't be crashing in the first place.

Jalal Hajigholamali Permalink
July 12, 2014, 12:23


As you know, init dead and systemd / upstart
have better architectures ...
if possible create unkillable process under
systemd and upstart

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "cloud_279": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.