I added an antry in /etc/inittab to respawn a binary. The entry is like:


I then execute init q and the process is started by inittab. If I kill the process, it's respawned.

The problem

The strange behaviour happens when I do the following:

  1. manually run /path-to-my-binary
  2. add the entry above in /etc/inittab
  3. run init q

Result: the process is respawned even though it was already running.

Moreover, if the binary was set to be run on startup with init.d, at runlevel 2, the inittab respawns it immediately at boot.


The simple answer is: Don't do it this way.

If you want to have your process handled according to the configuration in /etc/inittab you must not start it manually or somewhere else.

init does not check existing processes if there is a match bewtween the process' command and an entry in inittab. It only monitors its children, i.e. processes started by init itself.
When you run init q, the init process knows that it has not (yet) started a process for your line id:2:respawn:/path-to-my-bin and starts it.

Unfortunately I don't know where this is explicitly specified.
For me it is clear that it must be this way for several reasons:

  1. init will get a signal when a child process terminates, so it can get the status of the process, check the specification from inittab and restart the process if necessary. This is event based. For unrelated processes this would not be possible, so init would have to check all processes. This probably would be polling.
  2. init doesn't know what is intended with a separate process executing the same command as one of the inittab lines. It may or may not be desired behavior to run a second instance of the process.
  3. What would you expect init to do if you start the program manually after init has already started an instance according to inittab? What if the process started by inittab would terminate later? Or if the other process terminated later?

As there are many open questions it is natural for init to handle its child processes only and to ignore any unrelated process.

  • 1
    Thank you. Where can I find specific documentation about this behavior? It's not stated in the inittab man page. – Federico Taschin Mar 21 at 13:56
  • Ok, your points are very reasonable. – Federico Taschin Mar 21 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.