How to prevent a background process from being stopped after closing SSH client in Linux

前端 未结 20 1563
悲&欢浪女
悲&欢浪女 2020-11-22 06:16

I\'m working on a Linux machine through SSH (Putty). I need to leave a process running during the night, so I thought I could do that by starting the process in background (

20条回答
  •  無奈伤痛
    2020-11-22 07:09

    Nohup allows a client process to not be killed if a the parent process is killed, for argument when you logout. Even better still use:

    nohup /bin/sh -c "echo \$\$ > $pidfile; exec $FOO_BIN $FOO_CONFIG  " > /dev/null
    

    Nohup makes the process you start immune to termination which your SSH session and its child processes are kill upon you logging out. The command i gave provides you with a way you can store the pid of the application in a pid file so that you can correcly kill it later and allows the process to run after you have logged out.

提交回复
热议问题