'\" te .\" Copyright (c) 2010, 2012, Oracle and/or its affiliates.All rights reserved. .\" Copyright 1989 AT&T .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH nohup 1 "2012 年 2 月 7 日" "SunOS 5.11" "用户命令" .SH 名称 nohup \- 运行不受挂起影响的命令 .SH 用法概要 .LP .nf \fB/usr/bin/nohup\fR \fIcommand\fR [\fIargument\fR]... .fi .LP .nf \fB/usr/bin/nohup\fR \fB-p\fR [\fB-Fa\fR] \fIpid\fR [\fIpid\fR]... .fi .LP .nf \fB/usr/bin/nohup\fR \fB-g\fR [\fB-Fa\fR] \fIgpid\fR [\fIgpid\fR]... .fi .LP .nf \fB/usr/xpg4/bin/nohup\fR \fIcommand\fR [\fIargument\fR]... .fi .SH 描述 .sp .LP \fBnohup\fR 实用程序会调用提供了参数的指定 \fIcommand\fR。调用 \fIcommand\fR 时,\fBnohup\fR 会安排进程忽略 \fBSIGHUP\fR 信号。 .sp .LP 如果调用时使用了 \fB-p\fR 或 \fB-g\fR 标志,\fBnohup\fR 会安排由进程 \fBID\fR 列表或进程组 \fBID\fR 列表标识的已运行进程变得不受挂起影响。 .sp .LP 已知 \fIcommand\fR 需要运行很长时间并且用户希望退出终端时,可以使用 \fBnohup\fR 实用程序。shell 退出时,系统会向其子进程发送 \fBSIGHUP\fR 信号,缺省情况下,这会导致这些进程中止。如果调用作业时在前面加上了 \fBnohup\fR 命令,或者如果进程通过编程的方式选择忽略 \fBSIGHUP\fR,所有已停止作业、正在运行的作业和后台作业都会忽略 \fBSIGHUP\fR。 .sp .LP \fBnohup\fR 实用程序会使进程忽略 \fBSIGHUP\fR,但不会以任何方式保护这些进程不受其他信号影响。由于现代 shell 有时会在注销时发送除 \fBSIGHUP\fR 以外的信号,因此在 \fB/usr/bin/nohup\fR 下运行的作业有可能在控制 shell 退出时中止。 .sp .ne 2 .mk .na \fB\fB/usr/bin/nohup\fR\fR .ad .RS 27n .rt \fB/usr/bin/nohup\fR 运行的进程不受 \fBSIGHUP\fR(挂起)和 \fBSIGQUIT\fR(退出)信号影响。 .RE .sp .ne 2 .mk .na \fB\fB/usr/bin/nohup\fR \fB-p\fR [\fB-Fa\fR]\fR .ad .RS 27n .rt 使 \fBID\fR 指定的进程不受 \fBSIGHUP\fR 和 \fBSIGQUIT\fR 影响,并且将控制终端的所有输出重定向到 \fBnohup.out\fR。如果指定 \fB-F\fR,\fBnohup\fR 会强制控制每个进程。如果指定 \fB-a\fR,\fBnohup\fR 会更改 \fBSIGHUP\fR 和 \fBSIGQUIT\fR 的信号处理,即便进程已为任一信号安装了处理程序。 .RE .sp .ne 2 .mk .na \fB\fB/usr/bin/nohup\fR \fB-g\fR [\fB-Fa\fR]\fR .ad .RS 27n .rt 使与 \fBID\fR 指定的进程同属一个进程组的每个进程都不受 \fBSIGHUP\fR 和 \fBSIGQUIT\fR 影响,并且将控制终端的所有输出重定向到 \fBnohup.out\fR。如果指定 \fB-F\fR,\fBnohup\fR 会强制控制每个进程。如果指定 \fB-a\fR,\fBnohup\fR 会更改 \fBSIGHUP\fR 和 \fBSIGQUIT\fR 的信号处理,即便进程已为任一信号安装了处理程序。 .RE .sp .ne 2 .mk .na \fB\fB/usr/xpg4/bin/nohup\fR\fR .ad .RS 27n .rt \fB/usr/xpg4/bin/nohup\fR 运行的进程不受 \fBSIGHUP\fR 影响。 .sp \fBnohup\fR 实用程序不会安排进程不受 \fBSIGTERM\fR(终止)信号影响,因此,除非安排它们不受 \fBSIGTERM\fR 影响,或者 shell 使它们不受 \fBSIGTERM\fR 影响,否则它们会收到此信号。 .sp 如果 \fBnohup.out\fR 不可在当前目录中写入,系统会将输出重定向到 \fB$HOME/nohup.out\fR。如果创建了文件,此文件将具备读取和写入权限(\fB600\fR)。请参见 \fBchmod\fR(1)。如果标准错误为终端,系统会将其重定向到标准输出,否则不会重定向。\fBnohup\fR 运行的进程的优先级不会改变。 .RE .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-a\fR\fR .ad .RS 6n .rt 总是改变目标进程的信号处理。此选项仅在指定了 \fB-p\fR 或 \fB-g\fR 时有效。 .RE .sp .ne 2 .mk .na \fB\fB-F\fR\fR .ad .RS 6n .rt 强制。抓取目标进程,即使另一进程已掌握了控制权。此选项仅在指定了 \fB-p\fR 或 \fB-g\fR 时有效。 .RE .sp .ne 2 .mk .na \fB\fB-g\fR\fR .ad .RS 6n .rt 对进程组列表执行操作。此选项对 \fB-p\fR 无效。 .RE .sp .ne 2 .mk .na \fB\fB-p\fR\fR .ad .RS 6n .rt 对进程列表执行操作。使用 \fB-g\fR 时此选项无效。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIpid\fR\fR .ad .RS 12n .rt 要由 \fBnohup\fR \fB-p\fR 操控的十进制进程 \fBID\fR。 .RE .sp .ne 2 .mk .na \fB\fIpgid\fR\fR .ad .RS 12n .rt 要由 \fBnohup\fR \fB-g\fR 操控的十进制进程组 \fBID\fR。 .RE .sp .ne 2 .mk .na \fB\fIcommand\fR\fR .ad .RS 12n .rt 要调用的命令的名称。如果 \fIcommand\fR 操作数指定了任何特殊的 \fBshell_builtins\fR(1) 实用程序,将会产生无法预料的结果。 .RE .sp .ne 2 .mk .na \fB\fIargument\fR\fR .ad .RS 12n .rt 调用 \fIcommand\fR 操作数时作为参数提供的任何字符串。 .RE .SH 用法 .sp .LP 使用 \fB-F\fR 标志时应谨慎。在一个被调试的进程上施加两个控制进程可能会导致混乱。仅当主控制进程(通常是调试器)已停止了被调试的进程,并且在应用 \fBproc\fR 工具的可疑时刻主控制进程未在执行任何操作,才能保证安全。 .SH 示例 .LP \fB示例 1 \fR将 \fBnohup\fR 应用到管道或命令列表 .sp .LP 用户往往需要将 \fBnohup\fR 应用到管道或命令列表。为此,可以将管道和命令列表放在一个称作 shell 脚本的文件中。接着,用户可以发出: .sp .in +2 .nf example$ \fBnohup sh \fIfile\fR\fR .fi .in -2 .sp .sp .LP 此时便会将 \fBnohup\fR 应用到 \fIfile\fR 中的全部内容。如果要经常执行 shell 脚本 \fIfile\fR,则可以为 \fIfile\fR 授予执行权限,从而避免键入 \fBsh\fR。 .sp .LP 添加和符号时,\fIfile\fR 中的内容会在后台运行,同时忽略中断(请参见 \fBsh\fR(1)): .sp .in +2 .nf example$ \fBnohup \fIfile\fR &\fR .fi .in -2 .sp .LP \fB示例 2 \fR将 \fBnohup -p\fR 应用到进程 .sp .in +2 .nf example$ \fBlong_running_command &\fR example$ \fBnohup -p `pgrep long_running_command`\fR .fi .in -2 .sp .LP \fB示例 3 \fR将 \fBnohup -g\fR 应用到进程组 .sp .in +2 .nf example$ \fBmake &\fR example$ \fBps -o sid -p $$\fR SID 81079 example$ \fBnohup -g `pgrep -s 81079 make`\fR .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBnohup\fR 执行的 \fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR、\fBPATH\fR、\fBNLSPATH\fR 和 \fBPATH\fR 环境变量的说明,请参见 \fBenviron\fR(5)。 .sp .ne 2 .mk .na \fB\fBHOME\fR\fR .ad .RS 8n .rt 确定用户起始目录的路径名:如果不能在当前目录中创建输出文件 \fBnohup.out\fR,\fBnohup\fR 命令会使用 \fBHOME\fR 指定的目录创建该文件。 .RE .SH 退出状态 .sp .LP 将返回以下退出值: .sp .ne 2 .mk .na \fB\fB126\fR\fR .ad .RS 7n .rt 找到了 \fIcommand\fR,但无法调用。 .RE .sp .ne 2 .mk .na \fB\fB127\fR\fR .ad .RS 7n .rt \fBnohup\fR 中发生错误,或者找不到 \fIcommand\fR .RE .sp .LP 否则,\fBnohup\fR 退出值即为 \fIcommand\fR 操作数的退出值。 .SH 文件 .sp .ne 2 .mk .na \fB\fBnohup.out\fR\fR .ad .RS 19n .rt 标准输出为终端并且当前目录可写入时执行 \fBnohup\fR 的输出文件。 .RE .sp .ne 2 .mk .na \fB\fB$HOME/nohup.out\fR\fR .ad .RS 19n .rt 标准输出为终端并且当前目录不可写入时执行 \fBnohup\fR 的输出文件。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/nohup" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) .TE .SS "/usr/xpg4/bin/nohup" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBbash\fR(1)、\fBbatch\fR(1)、\fBchmod\fR(1)、\fBcsh\fR(1)、\fBdisown\fR(1)、\fBksh88\fR(1)、\fBnice\fR(1)、\fBpgrep\fR(1)、\fBproc\fR(1)、\fBps\fR(1)、\fBsh\fR(1)、\fBshell_builtins\fR(1)、\fBsetpgrp\fR(1)、\fBsignal\fR(3C)、\fBproc\fR(4)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5) .SH 警告 .sp .LP 如果正在将 Korn shell (\fBksh88\fR(1)) 作为登录 shell 运行,并且尝试退出时系统中含有运行了 \fBnohup\fR 的作业,您会收到一条警告消息: .sp .in +2 .nf You have jobs running. .fi .in -2 .sp .sp .LP 此时,您需要再次退出才能真正退出。不过,后台作业会继续运行。 .SH 附注 .sp .LP C-shell (\fBcsh\fR(1)) 含有内置的 \fBnohup\fR 命令,该命令可以让进程不受 \fBSIGHUP\fR 影响,但不会将输出重定向到 \fBnohup.out\fR。执行时指定了 "\fB&\fR" 的命令能够自动避免受到 \fBHUP\fR 信号的影响,同时又会在后台运行。 .sp .LP \fBnohup\fR 不能识别命令序列。执行以下命令时: .sp .in +2 .nf example$ \fBnohup command1; command2\fR .fi .in -2 .sp .sp .LP \fBnohup\fR 实用程序仅应用于 \fBcommand1\fR。命令: .sp .in +2 .nf example$ \fBnohup (command1; command2)\fR .fi .in -2 .sp .sp .LP 的语法错误。