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

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.

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.

rav Permalink
June 28, 2014, 08:09

Free Download Apps on PC
check my site

Jalal Hajigholamali Permalink
July 12, 2014, 12:23

Hi,

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

Jaavar Permalink
November 27, 2014, 18:19

Nice command /etc/inittab which respawn the programs. Before to this i was using supervisor to respawn the programs. Nice post thanks for sharing with us. Meanwhile here are details of State Bank of India all Branches and its detailed information Visit this page.

November 29, 2014, 08:56

Information on this site is helpful. I hope this site will have more progress

November 29, 2014, 09:00

Information on this site is helpful. I hope this site will have more progress

Kaur deep Permalink
December 04, 2014, 03:09

Excellent and knowledgeable links and post.thanks for sharing.
Now, The Time has come for the Happy New Year 2015. It wil bring a lot fo happinesin our life.
Happy New Year 2015
And I am sure, You wil anjoy this new year day with yoru fiends and wil send some images wishes,
New Year 2015

Happy New Year 2015 Wishes
Greetings to yoru close ones, Your friends, You lover, etc..
Happy New Year 2015 Images
Even I am waititng for that day, because it just changes our life.
Happy New Year 2015 Greetings

Happy New Year 2015 SMS
So, That's why I am commenting here to wish you a very happy new year.
Happy New Year 2015 Messages
I hope this New year 2015 wil bring success to your website. But before that Merry Christmas is coming.
Merry Christmas Quotes
It is also a big event for everyone.
Merry Christmas Pictures
Everyone knows that Christmas is a day when People seems to be very happy, they just leave all sadness behind.
Merry Christmas Wallpapers
And I am sure, you also enjoy this Merry Christmas day of 2014.
Christmas day Images

Christmas stocking
But if you are not looking out to enjoy this christmas, then you are missing out on a big thing, because it really brings happiness.
Merry Christmas Images

Merry Christmas 2014
So, what you are waiting for?
Merry Christmas 2015
Enjoy This Merry Christmas day. Cheers :).

Harsha Kumar Permalink
December 14, 2014, 20:06

This is really nice initiative /etc/inittab. I Like your post. Thanks for the post and at the same time have a look at Guideliness to find SBI branch details of Kalipur Bhutnath.

Diana Permalink
December 17, 2014, 15:53

This article is quite helpful and informative too. I enjoyed a lot. Thanks for sharing such a great article.

Beautiful Christmas Quotes for your friends and family...
christmas quotes
Christmas Messages for Whatsapp

Best Christmas Greetings for your friends and family...
christmas greeting
christmas wishes

What to Write in Christmas Card....... Check out best Christmas Greeting Card Words
What to Write in Christmas Card

Get Beautiful and Unique Christmas Wallpapers for free
free christmas wallpaper
christmas tree decorating ideas

Thanks for sharing such a great article.

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 "coding_279": (just to make sure you're a human)

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

Advertisements