Does linux kill background processes if we close the terminal from which it has started?

后端 未结 4 746
傲寒
傲寒 2021-01-30 17:59

I have an embedded system, on which I do telnet and then I run an application in background:

./app_name &

Now if I close my te

4条回答
  •  [愿得一人]
    2021-01-30 18:29

    In order completely understand whats happening you need to get into unix internals a little bit.

    When you are running a command like this

    ./app_name &

    The app_name is sent to background process group. You can check about unix process groups here

    When you close bash with normal exit it triggers SIGHUP hangup signal to all its jobs. Some information on unix job control is here.

    In order to keep your app running when you exit bash you need to make your app immune to hangup signal with nohup utility.

    nohup - run a command immune to hangups, with output to a non-tty

    And finally this is how you need to do it.

    nohup app_name & 2> /dev/null;

提交回复
热议问题