linux - running process background

后端 未结 3 1757
陌清茗
陌清茗 2021-01-13 03:05

I want to run a process in a remote linux server and keep that process alive after close the putty terminal,

what is the correct command?

相关标签:
3条回答
  • 2021-01-13 03:28

    You have two options:

    1. Use GNU screen, which will allow you to run the command and detach it from your terminal, and later re-attach it to a different session. I use it for long-running processes whose output I want to be able to monitor at any time. Screen is a truly powerful tool and I would highly recommend spending some time to learn it.
    2. Run the command as nohup some-command &, which will run the command in the background, detach it from the console, and redirect its output into nohup.out. It will swallow SIGHUPs that are sent to the process. (When you close the terminal or log out, SIGHUP is sent to all processes that were started by the login shell, and the default action the kernel will take is to kill the process off. This is why appending & to put the process in the background is not enough for it to survive a logout.)
    0 讨论(0)
  • 2021-01-13 03:31

    don't use that nohup junk, i hate seeing that on servers; screen is a wasting pile of bits and rot -- use tmux.

    if you want to background a process, double fork like every other daemon since the beginning of time:

    # ((exec sleep 30)&)
    # grep PPid /proc/`pgrep sleep`/status
    PPid:   1
    # jobs
    # disown
    bash: disown: current: no such job
    

    enjoy.

    0 讨论(0)
  • 2021-01-13 03:44

    A command launched enclosed in parenthesis

    (command &)
    

    will survive the death of the originating shell.

    0 讨论(0)
提交回复
热议问题