我想运行一个脚本,该脚本将放弃已运行10个以上CPU分钟的所有正在运行的作业。任何建议如何做到这一点。因此,我想这将涉及列出所有运行超过10分钟的作业,然后发出命令
for i in pidlist
do
renice $i
done
但是,我如何获得pidlist?
谢谢!
编辑:我正在尝试以下作为根:
ps -e -o pid,uid,nice,cputime= | awk '{gsub(/:/, "", $4); if (($1 > 1024) && ($2 >= 1000) && ($4 > 10) && ($3 <= 0)) print}'
我得到以下列表:
1679 1000 0 230641
但是,在没有条件的情况下,这是我得到的:
ps -e -o pid,uid,nice,cputime= | awk '{gsub(/:/, "", $4); if (($2 >= 1000) && ($4 > 0) && ($3 <= 0)) print}'
我得到:
1499 1000 0 000000
1501 1000 0 000000
1504 1000 0 000015
1529 1001 0 002238
1531 1000 0 000000
1532 1000 0 000000
1603 1000 0 000000
1607 1000 0 000000
1653 1000 0 000001
1667 1000 0 000000
1669 1000 0 000001
1672 1000 0 003817
1673 1000 0 000004
1675 1000 0 000000
1677 1000 0 000000
1678 1000 0 035431
1679 1000 0 230641
1694 1000 -11 000003
1716 1000 0 000000
1745 1000 0 000001
1748 1000 0 000006
1792 1000 0 000000
1983 1001 0 002207
2744 1000 0 000000
2745 1000 0 000010
2746 1000 0 000014
2747 1000 0 000000
2748 1000 0 000000
2876 1000 0 000000
2968 1000 0 000000
3111 1001 0 000000
3120 1001 0 000000
3614 1000 0 000010
3615 1000 0 000000
3616 1000 0 000000
3624 1000 0 000000
4326 1000 0 000000
4328 1000 0 000000
5574 1000 0 000001
5575 1000 0 000000
5576 1000 0 000000
6631 1000 0 034310
7729 1000 0 000002
9358 1001 0 001215
9453 1001 0 001212
11437 1001 0 000000
11971 1000 0 000000
13508 1001 0 000134
15130 1001 0 003458
16713 1000 0 000000
16715 1000 0 000043
20105 1001 0 000004
20111 1001 0 000021
22670 1000 0 000000
23496 1000 0 000000
23526 1000 0 000000
23865 1001 0 000755
24137 1001 0 000003
25023 1001 0 000631
25057 1001 0 000626
25660 1001 0 000538
26310 1001 0 000104
26354 1001 0 000441
26506 1000 0 000000
26724 1001 0 000411
26802 1000 0 000000
27071 1001 0 000041
这些过程中的某些过程显然满足了条件。那为什么不显示呢?我究竟做错了什么?
再次感谢!27082 1001 0 003040 27426 1001 0 000317 29626 1001 0 002744 31705 1001 0 002531 32090 1000 0 000008 32091 1000 0 000000 32092 1000 0 000000 32760 1001 0 000040
您ps
不仅要获取时间,还要获得作业已经被获取的时间nice
。另外,您可能不想弄乱编号较低的进程。正如larsks所述,它awk
是处理以下内容中基于列的输出的好工具ps
:
# get the output from ps; setting column name to empty string suppresses header
ps -e -o pid= -o cputime= -o nice= |
# replace the colons so time is a plain number; omit system and already nice processes
awk '{gsub(/:/, "", $2); time = $2 + 0; if ($1 > 1024 && time > 1000 && $3 <= 0) print $1}' |
# renice the ones left
xargs renice +10
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句