我发出^z; bg; disown ^z; bg; disown 为了让我closures一个ssh会话,我正在运行一个超重要的长时间运行的进程。 这个过程将状态输出写入stderr,并且即使在分离之后,它也继续这样做(用lsofvalidation,stderr fd打开r / w)。
有没有办法确定这个过程确实是不被接受的(如果shell调用一个,不会收到SIGHUP)?
在Bash中,由自己发出的disown命令将从活动作业表中删除后台(通过bg或& )进程,并将其标记为在注销时不会收到SIGHUP。
你也可以传递一个或多个工作,如disown 1 3 。 如果你想保留表中的工作,但是在注销时仍然没有SIGHUP,那么disown -h标志是有用的。
您可以通过发出jobs命令来查看作业表。 成功的背景后,会显示[1]+ command & 。 离职后,不应再显示在工作表中,不再在注销时被杀害。 您仍然可以通过ps ux , top和其他进程查看实用程序查看进程。
在一个工作被拒绝后,你可以等待它自然终止,或通过kill发送一个信号给PID来停止它。
由于Bash只是从正在运行的作业列表中删除作业来终止,并且文件处理到您的terminal的stdout和stderr仍处于打开状态,您将继续接收作业的输出,直到terminal设备closures(当您注销时) 。
例子:
# we start a command in the background $ cat /dev/urandom > test & [1] 18533 # we see our command is still running $ jobs [1]+ Running cat /dev/urandom > test & # we disown the backgrounded job $ disown 1 # notice it is no longer in the job table $ jobs
我通常只使用disown如果我运行一个像rsync或cp这样的可能长时间运行的命令,然后决定我需要退出而不终止它。 如果你知道要运行一个命令并注销,你可以通过pipe道获取输出,或者将其input到一个文件中,用nohup运行它,或者在screen运行它(这可以让你重新获得命令的所有权/之后终止)。
例子:
# capture stdout and stderr to separate logs cat /dev/urandom >stdout.log 2>stderr.log # capture stdout and stderr to the same log, and display to stdout as well cat /dev/urandom 2>&1 | tee output.log # run a command under nohup (doesn't require a disown or job control support) nohup cat /dev/urandom </dev/null