我有一个已经运行了很长时间的进程,不想结束它。
我如何把它放在nohup下(也就是说,我如何使它继续运行,即使我关闭了终端?)
我有一个已经运行了很长时间的进程,不想结束它。
我如何把它放在nohup下(也就是说,我如何使它继续运行,即使我关闭了终端?)
当前回答
假设由于某些原因Ctrl+Z也不能工作,转到另一个终端,找到进程id(使用ps)并运行:
kill -SIGSTOP PID
kill -SIGCONT PID
SIGSTOP将挂起进程,SIGCONT将在后台恢复进程。所以现在,关闭两个终端不会停止进程。
其他回答
假设由于某些原因Ctrl+Z也不能工作,转到另一个终端,找到进程id(使用ps)并运行:
kill -SIGSTOP PID
kill -SIGCONT PID
SIGSTOP将挂起进程,SIGCONT将在后台恢复进程。所以现在,关闭两个终端不会停止进程。
不幸的是,disown是bash特有的,并不是在所有shell中都可用。
某些类型的Unix(例如AIX和Solaris)在nohup命令本身上有一个选项,可以应用于正在运行的进程:
nohup -p pid
参见http://en.wikipedia.org/wiki/Nohup
在我的AIX系统上,我尝试了一下
nohup -p processid>
这很有效。它继续运行我的进程,即使关闭终端窗口。我们有ksh作为默认shell,所以bg和disown命令不起作用。
将正在运行的进程发送到nohup (http://en.wikipedia.org/wiki/Nohup)
Nohup -p pid,它对我不起作用
然后我尝试了下面的命令,它工作得很好
运行some somcommand, 输入/usr/bin/python /vol/scripts/python_scripts/retention_all_properties.py。 按Ctrl+Z停止(暂停)程序并返回shell。 Bg在后台运行它。 否认-h,这样当终端关闭时进程不会被终止。 输入exit退出shell,因为现在你已经准备好了,因为操作将在后台自己的进程中运行,所以它没有绑定到shell。
这个过程相当于运行nohup somcommand。
将正在运行的作业从shell中分离(=使其成为nohup)的命令是disown,是一个基本的shell命令。
来自bash-manpage (man bash):
disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.
这意味着,这是一个简单的
disown -a
将从工作表中删除所有的工作并使它们nohup