nohup
文章目录
nohup
nohup is a POSIX command to ignore the HUP (hangup) signal.
& would run the process in background using a subshell.
$ 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 an unreadable file.
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.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/nohup>
or available locally via: info '(coreutils) nohup invocation'
sh myprocess.sh
sh myprocess.sh &
# kill -HUP 可以杀死
nohup sh myprocess.sh
# kill -HUP 杀不死,kill -TERM可以杀死,kill -KILL可以杀死
nohup sh myprocess.sh &
# kill -HUP 杀不死,kill -TERM可以杀死,kill -KILL可以杀死
Name Num Action Description
0 0 n/a exit code indicates if a signal may be sent
ALRM 14 exit
HUP 1 exit
INT 2 exit
KILL 9 exit cannot be blocked
PIPE 13 exit
POLL exit
PROF exit
TERM 15 exit
USR1 exit
USR2 exit
VTALRM exit
STKFLT exit might not be implemented
PWR ignore might exit on some systems
WINCH ignore
CHLD ignore
URG ignore
TSTP stop might interact with the shell
TTIN stop might interact with the shell
TTOU stop might interact with the shell
STOP stop cannot be blocked
CONT restart continue if stopped, otherwise ignore
ABRT 6 core
FPE 8 core
ILL 4 core
QUIT 3 core
SEGV 11 core
TRAP 5 core
SYS core might not be implemented
EMT core might not be implemented
BUS core core dump might fail
XCPU core core dump might fail
XFSZ core core dump might fail
io-redirection
0: 标准输入(stdin)
1: 标准输出(stdout)
2: 标准错误(stderr)
ls a b 1>f.out 2>f.err
# 标准输出到f.out, 标准错误到 f.err
通常`1>`省略成`>`
ls a b 1>f.out 2>&1
# stdout、stderr到f.out
ls a b 2>f.out 1>&2
# stdout、stderr到f.out
&是一个描述符,如果1或2前不加&,会被当成一个普通文件
> 1> 的简写
1>&2 标准输出重定向到标准错误
2>&1 标准错误重定向到标准输出
&> file 把标准输出和标准错误输出都重定向到文件file中
>& file 把标准输出和标准错误输出都重定向到文件file中
# # stdout、stderr到/dev/null,/dev/null代表黑洞
>& /dev/null
&> /dev/null
2> /dev/null 1>&2
1> /dev/null 2>&1
> /dev/null 2>&1
ref
上次更新 2017-02-04
原始文档 查看本文 Markdown 版本 »