Linux "ps" command
September 03, 2004 02:34 AM
I think the ps command doesn't work very well because I want to see the current cpu usage from certain processes. When I create a webpage that loops infinitely the ps commando still says that apache is using 0.0%.
ps -eo "%cpu %C %U %c %a" | grep apache
(I also tried different options, without success)
In the ps manpage I see this text:
"%CPU shows the cputime/realtime percentage. It will not add up to 100% unless you are lucky. It is time used divided by the time the process has been running."
.... Well I ain't lucky. Is there a way to see the real cpu usage and not the average?
The "top" command shows the real cpu usage but I need its output to create a table for a webpage instead of seeing the top command continuesly.
If the "top" command shows the correct result you can just use something like this:
top -b -n 1 | grep apache
Check "man top" for more information. I'm basically starting top in batch mode and running it for a single iteration.
You probably cheched this, but note that if the webpage loop is client-side your server will not get hurt.
top -b -n 1 | grep apache
Check "man top" for more information. I'm basically starting top in batch mode and running it for a single iteration.
You probably cheched this, but note that if the webpage loop is client-side your server will not get hurt.
Thomas - www.moelhave.dk
i tried this command, and it shows a list of apache processes running at 0.0, and one of them at 0.1.
actually apache doesn't need any resources, unless you really have a big server load. so a CPU load of 0.0 seems ok to me (and if i run top, apache is so far at the bottom, that i cant see it).
but you can test your command like this: start a find to list all files; this eats a lot of CPU/IO:
find /
open another terminal and enter
ps -eo "%cpu %C %U %c %a" | grep find
gives me:
4.0 find pu 4.0 chris find find /
seems to work!
Chris
actually apache doesn't need any resources, unless you really have a big server load. so a CPU load of 0.0 seems ok to me (and if i run top, apache is so far at the bottom, that i cant see it).
but you can test your command like this: start a find to list all files; this eats a lot of CPU/IO:
find /
open another terminal and enter
ps -eo "%cpu %C %U %c %a" | grep find
gives me:
4.0 find pu 4.0 chris find find /
seems to work!
Chris
September 03, 2004 03:27 AM
Thanks dude. The "top" command does show the correct results, I just didn't know how to run it only once.
What do you mean by client-side? Anyway, when I load the webpage loop script "top" shows 99% cpu usage so that's correct.
And uh, what do you mean by client-side? I mean, the script runs on the server so isn't it always server-side?
(forgive my noobness :P)
edit: to the guy above:
The script is just a test to see if the commands show the correct results. When I load looping page apache has an cpu usage of 99%. When I use the "ps" command, it shows 0.0 and when I use "top" I see 99%. Kinda weird that the "ps" command show the cputime/realtime cpu usage.
What do you mean by client-side? Anyway, when I load the webpage loop script "top" shows 99% cpu usage so that's correct.
And uh, what do you mean by client-side? I mean, the script runs on the server so isn't it always server-side?
(forgive my noobness :P)
edit: to the guy above:
The script is just a test to see if the commands show the correct results. When I load looping page apache has an cpu usage of 99%. When I use the "ps" command, it shows 0.0 and when I use "top" I see 99%. Kinda weird that the "ps" command show the cputime/realtime cpu usage.
September 03, 2004 08:36 AM
One more thing, is it possible to get the correct CPU usage with the "ps" command? If it is, then that will save me some time editing my Perl script.
September 22, 2004 07:56 AM
Got the same problem with multithreaded program: ps shows the cpu usage of the main thread only !... The option -m gives the cpu usage by thread. It's better...
However, I haven't found a way to get the cpu usage by process without having to sum the thread cpu usages with a perl script...
However, I haven't found a way to get the cpu usage by process without having to sum the thread cpu usages with a perl script...
What about ps axu followed by | grep whatever?
tyler@localhost:~$ ps axuUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.0 1528 528 ? S 10:50 0:00 init [2]root 2 0.0 0.0 0 0 ? SN 10:50 0:00 [ksoftirqd/0]root 3 0.0 0.0 0 0 ? S< 10:50 0:00 [events/0]root 4 0.0 0.0 0 0 ? S< 10:50 0:00 [khelper]root 20 0.0 0.0 0 0 ? S< 10:50 0:00 [kblockd/0]root 50 0.0 0.0 0 0 ? S 10:50 0:00 [pdflush]root 51 0.0 0.0 0 0 ? S 10:50 0:00 [pdflush]root 53 0.0 0.0 0 0 ? S< 10:50 0:00 [aio/0]root 52 0.0 0.0 0 0 ? S 10:50 0:00 [kswapd0]root 189 0.0 0.0 0 0 ? S 10:50 0:00 [kseriod]root 210 0.0 0.0 0 0 ? S< 10:50 0:00 [ata/0]root 304 0.0 0.0 0 0 ? S 10:50 0:00 [kjournald]root 585 0.0 0.0 0 0 ? S 10:50 0:00 [khubd]root 2458 0.0 0.0 1700 696 ? Ss 10:51 0:00 dhclient -e -pf /daemon 2462 0.0 0.0 1640 444 ? Ss 10:51 0:00 /sbin/portmaproot 2627 0.0 0.0 1584 624 ? Ss 10:51 0:00 /sbin/syslogdroot 2630 0.0 0.1 2428 1444 ? Ss 10:51 0:00 /sbin/klogdDebian- 2664 0.0 0.1 4212 1472 ? Ss 10:51 0:00 /usr/sbin/exim4 -tyler 2669 0.0 0.1 2904 1472 ? Ss 10:51 0:00 /usr/sbin/famd -Twnn 2673 0.0 0.3 5276 3944 ? S 10:51 0:00 /usr/bin/Wnn4/jseroot 2680 0.0 0.0 1564 520 ? Ss 10:51 0:00 /usr/sbin/inetdroot 2687 0.0 0.1 3428 1444 ? Ss 10:51 0:00 /usr/sbin/sshdroot 2712 0.0 0.3 5016 3472 ? Ss 10:51 0:00 /usr/bin/X11/xfsroot 2784 0.0 0.1 2760 1460 ? S 10:51 0:00 /bin/bash /etc/rcroot 2785 0.0 0.1 2760 1460 ? S 10:51 0:00 /bin/bash /etc/rcroot 2786 0.0 0.2 9020 2760 ? S 10:51 0:00 /usr/bin/Xprt -acroot 2788 0.0 0.1 2760 1464 ? S 10:51 0:00 /bin/bash /etc/rcdaemon 2795 0.0 0.0 1716 628 ? Ss 10:51 0:00 /usr/sbin/atdroot 2855 0.0 0.0 1788 732 ? Ss 10:51 0:00 /usr/sbin/cronroot 2861 0.0 0.2 8860 2324 ? Ss 10:51 0:00 /usr/bin/gdmroot 2868 0.0 0.2 9204 2752 ? S 10:51 0:00 /usr/bin/gdmroot 2870 0.0 0.0 1528 480 tty1 Ss+ 10:51 0:00 /sbin/getty 38400root 2873 0.0 0.0 1528 480 tty4 Ss+ 10:51 0:00 /sbin/getty 38400root 2875 0.0 0.0 1528 484 tty6 Ss+ 10:51 0:00 /sbin/getty 38400root 2971 5.8 6.5 81604 67912 ? S<L 10:51 0:49 /usr/X11R6/bin/Xroot 3069 0.0 0.0 0 0 ? S 10:51 0:00 [kapmd]root 3102 0.0 0.0 1528 484 tty3 Ss+ 10:51 0:00 /sbin/getty 38400root 3128 0.0 0.0 1528 484 tty5 Ss+ 10:51 0:00 /sbin/getty 38400tyler 3165 0.0 0.8 18660 9324 ? Ss 10:51 0:00 /usr/bin/gnome-setyler 3229 0.0 0.0 3004 880 ? Ss 10:51 0:00 /usr/bin/ssh-agentyler 3232 0.1 0.7 10776 7476 ? S 10:51 0:01 /usr/lib/gconf2/gtyler 3234 0.0 0.0 2284 1020 ? S 10:51 0:00 /usr/bin/gnome-ketyler 3236 0.0 0.2 7112 2864 ? Ss 10:51 0:00 /usr/lib/bonobo-aroot 3237 0.0 0.0 1528 480 tty2 Ss+ 10:51 0:00 /sbin/getty 38400tyler 3249 0.0 0.2 7728 2684 ? Ss 10:51 0:00 gnome-smproxy --styler 3251 0.0 0.8 20372 8592 ? S 10:51 0:00 /usr/lib/control-tyler 3288 0.1 0.7 13704 7400 ? Ss 10:51 0:00 metacity --sm-savtyler 3299 0.0 1.1 20952 12348 ? Ss 10:51 0:00 gnome-panel --sm-tyler 3301 0.0 1.7 36076 17648 ? Ss 10:51 0:00 nautilus --sm-contyler 3303 4.6 3.2 77188 34168 ? Ss 10:51 0:38 /usr/bin/python /tyler 3305 0.1 0.7 46760 7636 ? Ss 10:51 0:00 xmms --sm-client-tyler 3310 0.0 0.3 17368 3612 ? S 10:51 0:00 /usr/lib/gnome-vftyler 3328 0.0 0.0 2220 764 ? S 10:51 0:00 /usr/lib/nautilustyler 3333 0.0 0.9 18220 9404 ? S 10:51 0:00 /usr/lib/gnome-patyler 3335 0.0 0.9 18136 9668 ? S 10:52 0:00 /usr/lib/gnome-patyler 3349 6.8 4.1 112656 42820 ? S 10:52 0:54 /usr/lib/mozilla-tyler 3575 0.0 0.1 3816 1924 ? S 10:56 0:00 /usr/bin/xscreenstyler 3781 17.5 1.2 31500 13248 ? R 11:05 0:00 gnome-terminaltyler 3782 0.0 0.0 2236 672 ? S 11:05 0:00 gnome-pty-helpertyler 3783 0.0 0.1 4824 1672 pts/1 Ss 11:05 0:00 bashtyler 3787 0.0 0.0 2528 848 pts/1 R+ 11:05 0:00 ps axu
Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement