ame*_*ior 21 bash daemon gnu-screen background-process job-control
如何运行shell脚本并立即对其进行后台处理,但是可以通过拖尾/tmp/output.txt随时检查其输出
如果我能在以后进行前瞻,那将是很好的.
PS如果您还可以向我展示如何将后台进程"发送"到可能已初始化或未初始化的gnu屏幕,那将是非常酷的.
Jon*_*ski 37
只需&
在命令后添加一个&符号().
如果程序写入标准输出,它仍将写入您的控制台/终端.
要前置该过程,只需使用该fg
命令即可.
(您可以在后台看到作业列表jobs
.)
例如:
sh -c 'sleep 3 && echo I just woke up' & jobs
如果您已在前台启动了该过程,但想要将其移至后台,则可以执行以下操作:
bg
命令以恢复该过程,但让它在后台而不是前台运行.一种允许管理多个进程并具有漂亮的终端 UI 的易于使用的方法是不幸的实用程序。
使用pip install hapless
(或python3 -m pip install hapless
) 安装并运行
$ hap run my-command # e.g. hap run python my_long_running_script.py
$ hap status # check all the launched processes
$ hap logs 4 # output logs for you 4th background process
$ hap logs -f 2 # continuously stream logs for the 2nd process
Run Code Online (Sandbox Code Playgroud)
请参阅文档以获取更多信息。
小智 6
Another way is using the nohup
command with &
at the end of the line.
Something like this
nohup whatevercommandyouwant whateverparameters &
Run Code Online (Sandbox Code Playgroud)
这将在后台运行它,并将其输出发送到nohup.log文件。