运行shell脚本并立即将其后台运行,但是保持检查其输出的能力 [英] run a shell script and immediately background it, however keep the ability to inspect its output
问题描述
如何运行shell脚本并立即使其后台运行,但是可以随时通过拖尾/tmp/output.txt来检查其输出的能力
How can I run a shell script and immediately background it, however keep the ability to inspect its output any time by tailing /tmp/output.txt
如果我可以过早地介绍该过程,那就太好了.
It would be nice if I can foreground the process too later.
PS,如果您还可以向我展示如何将后台进程发送"到可能尚未初始化的gnu屏幕中,那将非常酷.
PS It would be really cool if you can also show me how to "send" the backgrounded process in to a gnu screen that may or may not have been initialized.
推荐答案
在启动进程时使其后台"
在命令后只需添加一个&符即可.
To 'background' a process when you start it
Simply add an ampersand (&
) after the command.
如果程序写入标准输出,它仍将写入控制台/终端.
If the program writes to standard out, it will still write to your console/terminal.
只需使用fg
命令即可使该过程成为前台.
To foreground the process, simply use the fg
command.
(您可以使用jobs
在后台看到作业列表.)
(You can see a list of jobs in the background with jobs
.)
例如:
如果您已经在前台启动了该过程,但是想要将其移至后台,则可以执行以下操作:
If you have already started the process in the foreground, but you want to move it to the background, you can do the following:
- 按Ctrl + z可使当前进程进入睡眠状态并返回到您的shell. (此过程将暂停,直到您发送另一个信号为止.)
- 运行
bg
命令以恢复该过程,但使它在后台而不是在前台运行.
- Press Ctrl+z to put the current process to sleep and return to your shell. (This process will be paused until you send it another signal.)
- Run the
bg
command to resume the process, but have it run in the background instead of the foreground.
这篇关于运行shell脚本并立即将其后台运行,但是保持检查其输出的能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!