[英]How to run two commands together?
我编写了一个shell脚本(myScript.sh),其中包含以下格式的一组命令:
command1 #first run
command1 #second run
command1 #third run
现在,我想查找每个单独的command1运行消耗的最大RAM。 我可以通过在单独的终端中运行以下命令来找到命令1消耗的最大RAM:
smem -c "command pss" | grep "command1"
为了找到分别进行第一次,第二次和第三次运行所消耗的最大RAM,我以交错方式手动在不同终端上运行了run command1和smem
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory
command1 #terminal 1
smem -c "command pss" | grep "command1" #terminal 2 in a loop to get maximum memory/
有什么方法可以使用linux命令或python在单个shell脚本或程序中自动执行此过程?
不确定Linux,但您可以在Mac OS X下的Mac上执行此操作:
/usr/bin/time -l <command> 2>&1 | grep -i max
样本输出:
/usr/bin/time -l sleep 1 2>&1 | grep -i max
557056 maximum resident set size # <--- program used 557kB
或者,完整输出:
/usr/bin/time -l sleep 1
1.00 real 0.00 user 0.00 sys
557056 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
145 page reclaims
0 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
0 signals received
0 voluntary context switches
2 involuntary context switches
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.