Linux Driver

2016年7月16日 星期六

nohup 指令

如何使Process 成為 daemon ?

nohup 指令 (no hang up,不要掛斷)。當 使用ssh 登入linux後,一旦登出或關掉 ssh 軟體,那個在執行的程式就會結束,原因是它的parent process 被關閉了 (Session-->Bash shell --> your process)

nohup 可以讓ssh登出後, 仍保留程式繼續執行中 。但此程式的PPID (parent PID) 會掛在PID=1(即init 程式)

nohup sleep 100

登出後再進去看ps -aux 查看, PID 14128還在, 且可以ps -lx查到其PPID=1

nohup --help

Usage: nohup COMMAND [ARG]...
  or:  nohup OPTION
Run COMMAND, ignoring hangup signals.

      --help     display this help and exit
      --version  output version information and exit

If standard input is a terminal, redirect it from /dev/null.
If standard output is a terminal, append output to 'nohup.out' if possible,'$HOME/nohup.out' otherwise.
If standard error is a terminal, redirect it to standard output.
To save output to FILE, use 'nohup COMMAND > FILE'.

NOTE: your shell may have its own version of nohup, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.

Report nohup bugs to
GNU coreutils home page: <>
General help using GNU software: <>
For complete documentation, run: info coreutils 'nohup invocation'

沒有留言 :