用途
不挂断地运行命令。
语法
描述
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
参数指定命令的退出状态。
示例
1.
要在注销后在后台中运行命令,请输入:
2.
$ nohup find / -print &
输入该命令后,显示如下:
670
$ Sending output to nohup.out
进程 ID 号更改为 &(表示“and”的符号)启动的后台进程的 ID 号。消息
输出发送到 nohup.out
通知您来自
find / -print
命令的输出在
nohup.out
文件中。查看这些消息后可以注销,即使
find
命令仍在运行。
3.
要在后台中运行命令并将标准输出重定向到其他文件,请输入:
4.
$ nohup find / -print >filenames &
本例运行
find / -print
命令并且将输出存储到命名为
filenames
的文件中。现在只显示进程 ID 和提示:
677
$
因为
nohup
命令需要片刻时间来启动
Command
参数指定的命令,在注销前请等待。如果太快注销,
Command
参数指定的命令可能根本没运行。一旦
Command
参数指定的命令启动,注销就不会对其产生影响。
5.
要运行多条命令,则使用 shell 过程。例如,如果写 shell 过程:
6.
neqn math1 | nroff > fmath1
且命名它为
nnfmath1
文件,那么可以为
nnfmath1
文件中所有命令运行
nohup
命令,命令为:
nohup sh nnfmath1
7.
如果您将执行许可权分配到
nnfmath1
文件,发出此命令会得到相同的结果:
8.
nohup nnfmath1
9.
要在后台中运行
nnfmath1
文件,请输入:
nohup nnfmath1 &
10.
要在 Korn shell 程序中运行
nnfmath1
文件,请输入:
11.
nohup ksh nnfmath1
12.
要使运行的进程忽略所有挂起信号,请输入:
13.
nohup -p 161792
注意:
在*NIX平台下,目前用过的在SOLARIS/REDHAT,都可以直接用nohup ./startWebLogic.sh来启动进程,在AIX5.1下遇到问题,由于其缺省的是ksh,因此直接使用以上命令后在TELNET窗口断开后无法保持,因此可以通过以下命令来实现保证进程在断开窗口以后依然正常运行。
# ls
StartServer.bat conf lib nohup.out
StartServer.sh ivrserver.jar log
# csh
f280-003# nohup ./StartServer.sh &
[1] 17944
f280-003# log4j = /export/ivr/conf/log4j.properties
^C
f280-003# ksh
# ps -ef|grep java
root 17945 17944 0 14:37:34 ? 0:01 /usr/j2se/bin/java -Dfile.encoding=ISO-8859-1 -cp .:./lib/log4j-1.2.9.jar:./lib