2015-09-05 88 views
0

我写了一个shell脚本(myScript.sh),包括一组以下形式的命令的:如何一起运行两个命令?

command1 #first run 
command1 #second run 
command1 #third run 

现在我想找到的Command每个单独运行消耗的最大RAM。

smem -c "command pss" | grep "command1" 

为了找到通过首先消耗的最大RAM,第二和第三运行单独我有运行Command1和SMEM:我可以通过在 单独的终端运行命令找到命令1消耗的最大RAM上不同的终端手动以交错的方式

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单个外壳脚本或程序内自动执行此过程的任何方式?

回答

1

不知道关于Linux,但你可以在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