[英]Running a script with top command in the background
我有一个脚本,基本上每秒将top -n1
的 output 打印到文件中
最简单的形式:
while [ 1 ] ; do
top -n1
sleep 1
done
如果我像这样运行我的脚本:
./my_script.sh > out.log
它运行良好
如果我在后台运行它:
./my_script.sh > out.log &
然后它给了我Stopped(SIGTTOU)
错误。 从其他 Q/As 我发现 top 正在尝试从标准输入中读取,并且在后台运行时没有标准输入。
如何将 top 作为后台任务记录到文件中?
您需要将顶部写入文件,并且在循环中..
#!/bin/bash
while [ 1 ] ; do
top -b -n 1 > top.txt
sleep 1
done
或者
#!/bin/bash
while :
do
top -b -n 1 > top.txt
sleep 1
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.