top vs. ps : different output ?
Hi,I'm confused by different reported CPU% times for output of "top" and "ps"
I wrote an auto-kill script to kill processes that exceed a certain CPU% and run-time...but its failing because the output of "ps" is much below the output of "top" output.
Output of "top"....
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
4501 mysql 25 0 9480 9480 2196 R 46.0 0.9 8:38 mysqld
7661 mysql 25 0 9480 9480 2196 R 45.4 0.9 4:33 mysqld
Output of "ps" for same processes taken simultaneously in 2nd SSH window...
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 7661 1.8 0.9 39280 9388 ? R 07:21 4:16 /usr/libexec/mysqld --defaults-file=/etc/my.cnf
mysql 4501 6.2 0.9 39316 9420 ? R 08:54 8:25 /usr/libexec/mysqld --defaults-file=/etc/my.cnf
So, instead of 46.0 CPU% in "top" for process 7661, we have only 1.8 CPU% in "ps"...this anomaly is making my autokill script fail.
Any ideas on this...and which is the correct output ?