nohup 命令
用途
不挂断地运行命令。
语法
nohup { -p pid | Command [ Arg ... ] [ & ] }
描述
nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,同时忽略所有的挂起(SIGHUP)信号,或者修改用 -p 选项指定的进程来忽略所有的挂起(SIGHUP)信号。
在注销后还可以使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 &(表示“and”的符号)到命令的尾部。
注:
不能同时指定
-p pid 和 Command。
使用 -p pid 时,指定进程的输出将不会重定向到 nohup.out。
标志
-p pid | pid 是正在运行的进程的进程标识。nohup 命令修改指定进程来忽略所有的挂起(SIGHUP)信号。 |
退出状态
该命令返回下列出口值:
126 | 可以查找但不能调用 Command 参数指定的命令。 | 127 | nohup 命令发生错误或不能查找由 Command 参数指定的命令。 |
否则,nohup 命令的退出状态是 Command 参数指定命令的退出状态。
示例
- 要在注销后在后台中运行命令,请输入:
$ nohup find / -print & 输入该命令后,显示如下: 670
$ Sending output to nohup.out 进程 ID 号更改为 &(表示“and”的符号)启动的后台进程的 ID 号。消息 输出发送到 nohup.out 通知您来自 find / -print 命令的输出在 nohup.out 文件中。查看这些消息后可以注销,即使 find 命令仍在运行。 - 要在后台中运行命令并将标准输出重定向到其他文件,请输入:
$ nohup find / -print >filenames & 本例运行 find / -print 命令并且将输出存储到命名为 filenames 的文件中。现在只显示进程 ID 和提示: 677
$ 因为 nohup 命令需要片刻时间来启动 Command 参数指定的命令,在注销前请等待。如果太快注销,Command 参数指定的命令可能根本没运行。一旦 Command 参数指定的命令启动,注销就不会对其产生影响。 - 要运行多条命令,则使用 shell 过程。例如,如果写 shell 过程:
neqn math1 | nroff > fmath1 且命名它为 nnfmath1 文件,那么可以为 nnfmath1 文件中所有命令运行 nohup 命令,命令为: nohup sh nnfmath1 - 如果您将执行许可权分配到 nnfmath1 文件,发出此命令会得到相同的结果:
nohup nnfmath1 - 要在后台中运行 nnfmath1 文件,请输入:
nohup nnfmath1 &
- 要在 Korn shell 程序中运行 nnfmath1 文件,请输入:
nohup ksh nnfmath1 - 要使运行的进程忽略所有挂起信号,请输入:
nohup -p 161792
|
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7199859/viewspace-466425/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7199859/viewspace-466425/