bash脚本-如何获得运行过程的延时和参数
假设im运行的python脚本具有如下参数:bash脚本-如何获得运行过程的延时和参数,bash,shell,Bash,Shell,假设im运行的python脚本具有如下参数: 501 8694 8590 0 11:01PM ttys011 0:02.03 /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python test.py 100 yes 501 8699 8696 0 11:01PM ttys012 0:01.03 /Library/Frameworks/Py
501 8694 8590 0 11:01PM ttys011 0:02.03 /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python test.py 100 yes
501 8699 8696 0 11:01PM ttys012 0:01.03 /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python test.py 100 no
现在,我想使用bash脚本提取当前正在运行的两个进程,并获取每个进程已经运行的时间量和参数yes/no。这就是我到目前为止所做的,仅提取每个进程所花费的时间:
#!/bin/bash
commands=$(ps -ef | grep -v grep | grep "while-file")
var=0
for command in $commands;do
((var++))
if [ $var = 7 ];then
echo "time taken:$command"
fi
if [ $var = 17 ];then
echo "time taken:$command"
fi
done
但这并不干净。如果我碰巧有3个进程在运行,我的代码就会中断
因此,我的问题是:
如何获取每个进程已运行的时间量。在这种情况下,第一个进程已运行2min3sec,而第二个进程为1min3sec
我怎样才能从每一行中得到“是”或“否”的论点
-编辑-
好的,根据特瓦尔伯格的评论,我这样做了:
$ps -ef | grep [w]hile-file.py | awk '{print $7, $NF}'
0:00.00 while-file.py
0:00.02 yes
0:00.03 no
我如何忽略第一行:0:00.00 while file.py你能用time命令启动python进程吗?你使用哪个操作系统?嗯,对不起,我不确定这意味着什么?我目前正在mac osx中编码,但将部署到debianps-ef | grep[t]est.py | awk'{print$7,$NF}?不过,我不知道您的grep while文件是如何找到这些进程条目的。也许您只是部分损坏了脚本/输出。。。?