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:

uniq:3:respawn:/bin/unkillable

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.

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

Comments

February 01, 2014, 01:00

Nice trick. On Systemd based systems, you can correspondingly use "Restart" configuration option. (http://www.freedesktop.org/software/systemd/man/systemd.service.html). I think that will do the same.

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.

February 05, 2014, 16:51

Thank bro. good post. uniq:3:respawn:/bin/unkillable

February 27, 2014, 12:41

So really nice plan. Also want a great pozycjonowanie stron now

March 19, 2014, 06:43

For most quick video format conversions I turn to "M2TS video converter" (http://www.freem2tsconverter.com/). It handles most of the stuff I want to do when I don't want to get into the details of demuxing and encoding.

February 28, 2014, 16:03

Nice trick. On Systemd based systems, you can correspondingly use "Restart" configuration option.indian escort //
indian pakistani escort in dubai //
indian escort service //

March 04, 2014, 08:24

That seems to be so interesting and also we need a good help in bussiness

March 19, 2014, 06:31

Wow, I was looking for exactly this piece of software to help me figure out my oly form, thanks for sharing.

March 23, 2014, 02:29

Really nice information.. Thanks for sharing this wonderful

information...

April 10, 2014, 09:05

If you are planning to get the Canon C100 AVCHD to Avid MC, you will meet the same trouble with the old version.

April 14, 2014, 04:50

Anyone who believes they have been a target this type of attack should immediately contact their financial institutions and local FBI office, and promptly report it to the Internet Crime Complaint Center (IC3) Web site. The IC3 complaint database links complaints together to refer them to the appropriate law enforcement agency for case consideration. The IC3 also uses complaint information to identify emerging trends and patterns.

Leave a new comment

(why do I need your e-mail?)

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

Type the first letter of your name: (just to make sure you're a human)

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

Advertisements