use*_*951 20 command-line terminal exit background-process
在 Linux 中。假设我想运行一个命令,它花费的时间太长。我只是想确保它完成了。如何?
bsd*_*bsd 32
nohup
阅读手册页以了解nohup
用法。
nohup
是它已经做了长久以来前的样子screen
,tmux
等被发明。
例子:
nohup my_long_running_proc &
Run Code Online (Sandbox Code Playgroud)
运行“my_long_running_proc”,任何控制台(stdout/stderr)消息都会进入命令启动目录中名为“nohup.out”的文件中。
使用tmux
或screen
为命令运行提供持久会话环境。
使用tmux
,这可以通过以下方式完成:
tmux new -s my-session-name
longrunningcommand
tmux
使用Ctrl+b
,然后d
tmux attach-session -t my-session-name
tmux
可以做更多的事情,但可能应该添加一个基本的东西:tmux list-sessions
用于查看所有活动会话。
使用命令 xclock 测试它。打开控制台,输入
xclock
Run Code Online (Sandbox Code Playgroud)
关闭控制台。xclock 消失了。现在输入
xclock &
Run Code Online (Sandbox Code Playgroud)
xclock 仍然消失,因为它仍然是你的 shell 的一个子进程。现在输入
xclock & disown
Run Code Online (Sandbox Code Playgroud)
现在 xclock 不再是 shell 的子进程,您可以关闭控制台,xclock 将继续运行。
我在这里记录了这个:http : //www.linuxintro.org/wiki/Disown