如何消除任何东西

时间:2017-12-01 00:59:47

标签: linux scheduling policy

此代码向用户显示调度策略以及linux中每个活动进程的优先级。

#!/bin/bash
ps|awk '{print $1}' > temp.txt 
sed -i '/PID/'d ./temp.txt #deletes the first line that contains the word 'PID'
x=$(wc -w temp.txt|awk '{print $1}') #counts file's lines
for ((i=1;i<=$x;++i)) #for every pid executes the command chrt seperately
do
chrt -p $i > file_$i.txt #moves the result in a new file
y=$(wc -w file_$i.txt|awk '{print $1}') 
if [ y=2 ] #the results not containing errors are two lines, so i use the    command 'cat' to show the successful ones
then
    cat file_$i.txt
    rm file_$i.txt
else
        rm file_$i.txt
    fi
done

当我运行它时,我得到了这个:

pid 1's current scheduling policy: SCHED_OTHER
pid 1's current scheduling priority: 0
pid 2's current scheduling policy: SCHED_OTHER
pid 2's current scheduling priority: 0
chrt: failed to get pid 3's policy: No such process
pid 4's current scheduling policy: SCHED_OTHER
pid 4's current scheduling priority: 0

如何隐藏此失败的行(chrt:未能获得pid 3&#39; s政策:没有这样的过程)所以当somoene运行我的代码时不显示失败?

0 个答案:

没有答案