问题
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