linuxembedded-linuxinitbuildrootinittab

buildroot inittab spawns multiple processes even though its not dead


I have a buildroot inittab run by busybox init with following entry.

::respawn:/sbin/abcd -C /tmp/abc.conf

If I remove above line and start process manually, "/sbin/abcd -C /tmp/abc.conf" then it is created and single instance only as expected.

But with inittab entry it keeps on spawning multiple instance of abcd process.

ps aux | grep abcd
 1247 root     /sbin/abcd -C /tmp/abc.conf
 2223 root     /sbin/abcd -C /tmp/abc.conf
 2414 root     /sbin/abcd -C /tmp/abc.conf
 2503 root     /sbin/abcd -C /tmp/abc.conf
 2739 root     /sbin/abcd -C /tmp/abc.conf

Solution

  • EDIT to improve answer - original answer below.

    respawn means that the process is restarted as soon as it exits.

    If /sbin/abcd is a daemon, then it will probably daemonize itself, i.e. it will spawn a child and exit. This way, if it is launched from the shell, you can continue working while the daemon runs in the background.

    However, this means that for init, it seems like the process died and it will attempt to restart it. Since the daemon always exits immediately, it will keep on restarting more and more instances.

    To avoid this, make sure that the program does not daemonize. There are usually command line options for that.


    Original answer

    With "-d" option it works:

    ::respawn:/sbin/abcd -d -C /tmp/abc.conf
    

    No idea why it works. Did not have time to explore init behavior

    Update1: If process is started in daemon mode, init gets SIGCHLD after the first fork() and restarts the process. If in non daemon mode, init will bot get SIGCHLD.