如何将watch
命令与命令配合使用jobs
,以便可以监视后台作业的完成时间?
我按如下方式执行它,但是我没有从Jobs中获得输出:
watch jobs
如果我自己运行作业,那么我的测试后台作业将得到以下结果:
jobs
[1]+ Running nohup cat /dev/random >/dev/null &
该watch
命令的文档如下:
SYNOPSIS
watch [-dhvt] [-n <seconds>] [--differences[=cumulative]] [--help]
[--interval=<sec-onds>] [--no-title] [--version] <command>
[...]
NOTE
Note that command is given to "sh -c" which means that you may need to
use extra quoting to get the desired effect.
提供该命令的部分sh -c
表示jobs
您正在运行的命令watch
与生成该任务的外壳会话在不同的外壳会话中运行,因此无法看到其他外壳。从根本上讲,问题是这jobs
是内置的Shell,必须在产生您要查看的作业的Shell中运行。
您可以得到的最接近的结果是在产生任务的外壳程序中使用while循环:
$ while true; do jobs; sleep 10; done
您可以在shell启动脚本中定义一个函数,以使其更易于使用:
myjobwatch() { while true; do jobs; sleep 5; done; }
然后,您只需要输入即可myjobwatch
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句