nohup
rose1 发表于 2020-10-20 09:04浏览次数:
在类似Unix的操作系统上,nohup命令执行另一个命令,并指示系统即使会话断开连接也继续运行它。
本文档介绍了nohup的GNU / Linux版本。
On Unix-like operating systems, the nohup command executes another command, and instructs the system to continue running it even if the session is disconnected.
This document covers the GNU/Linux version of nohup.
目录:
1 nohup 运行系统环境
2 nohup 说明
3 nohup 语法
4 nohup 例子
nohup 运行系统环境
nohup 说明
使用命令外壳程序时,在命令前面加上nohup可以防止在注销或退出外壳程序时自动中止该命令。
nohup这个名字代表“没有挂断”。正常情况下,将挂断(HUP)信号发送给进程以通知用户已注销(或“挂断”),但nohup会截获该信号,从而允许进程继续运行。
When using the command shell, prefixing a command with nohup prevents the command from being aborted automatically when you log out or exit the shell.
The name nohup stands for "no hangup." The hangup (HUP) signal, which is normally sent to a process to inform it that the user has logged off (or "hung up"), is intercepted by nohup, allowing the process to continue running.
nohup 语法
nohup command [command-argument ...]
nohup --help | --version
选件
--help
|
显示帮助消息并退出。
|
--version
|
输出版本信息并退出。
|
笔记
如果标准输入是终端,则nohup 从/ dev / null重定向它。因此,使用nohup运行命令时,无法进行终端输入。
如果标准输出是终端,则命令输出将附加到文件nohup.out(如果可能),否则附加到$ HOME / nohup.out。
如果标准错误是终端,则将其重定向到标准输出。
要将输出保存到名为file的文件,请使用“ nohup 命令 > file ”。
nohup command [command-argument ...]
nohup --help | --version
Options
--help
|
Display a help message and exit.
|
--version
|
Output version information and exit.
|
Notes
If standard input is a terminal, nohup redirects it from /dev/null. Therefore, terminal input is not possible when running a command with nohup.
If standard output is a terminal, command output is appended to the file nohup.out if possible, or $HOME/nohup.out otherwise.
If standard error is a terminal, it is redirected to standard output.
To save output to a file named file, use "nohup command > file".
nohup 例子
nohup mycommand
运行命令mycommand。它不会接收输入。所有输出(包括任何错误消息)都将被写入工作目录或主目录中的文件nohup.out中。如果在注销或关闭终端时mycommand正在运行,则mycommand将不会终止。
nohup mycommand &
与上一个命令相同,但是这种形式(使用bash shell时)会立即使您返回到shell提示符。命令末尾的“ & ”符号指示bash在后台运行nohup mycommand。可以使用fgbash内置命令将其带回前台。
使用&时,您会在括号中看到bash作业ID,并在其后列出进程ID(PID)。例如:
[1] 25132
您可以使用PID提前终止进程。例如,使用kill命令向其发送TERM(终止)信号:
kill -9 25132
nohup mycommand
Run the command mycommand. It will not receive input. All output, including any error messages, will be written to the file nohup.out in the working directory, or in your home directory. If mycommand is running when you log out or close the terminal, mycommand will not terminate.
nohup mycommand &
Same as the previous command, but this form (when using the bashshell) returns you immediately to the shell prompt. The "&" symbol at the end of the command instructs bash to run nohup mycommand in the background. It can be brought back to the foreground with the fgbash builtin command.
When using &, you'll see the bash job ID in brackets, and the process ID (PID) listed after. For example:
[1] 25132
You can use the PID to terminate the process prematurely. For instance, to send it the TERM (terminate) signal with the kill command:
kill -9 25132