How to determine how much CPU load is produced from processes running under some user in Linux? [closed]

雨燕双飞 提交于 2021-02-08 05:15:42

问题


I would like to make a simple monitoring script that will record CPU load produced by user "abc" in a text file.

vmstat, iostat, mpstat and free do not seem to have a capability to filter based on user name.

Is it possible at all?

EDIT: Btw. I'm running on Red Hat EL 6.0.


回答1:


A simple way would be

top -b -n 1 -u abc | awk 'NR>7 { sum += $9; } END { print sum; }'

If you are interested in the cpu time on a per user basis you can also use acct.

accton on
sa -m



回答2:


You want to use the top command in batch mode and specify the user, number of iterations and maybe the duration (seconds). Depending on what you need it for, you might not even need a shell script as top has some very useful options. Check the man page.

top -u abc -d 30 -b -n 10



回答3:


top -o cpu -l 2 -U <username> -stats pid,command,cpu ought to do it. Ignore the first sample, as all the %CPU figures will be 0.



来源:https://stackoverflow.com/questions/6909546/how-to-determine-how-much-cpu-load-is-produced-from-processes-running-under-some

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!