{"id":913,"date":"2018-04-04T16:19:12","date_gmt":"2018-04-04T10:49:12","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=913"},"modified":"2018-08-06T09:53:44","modified_gmt":"2018-08-06T04:23:44","slug":"how-to-find-out-the-resourcecpu-memory-usages-of-users-in-centos","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/how-to-find-out-the-resourcecpu-memory-usages-of-users-in-centos\/","title":{"rendered":"How to find out the resource(cpu, memory) usages of users in Centos"},"content":{"rendered":"<p><strong>Find out the resource(cpu, memory) usages of users<\/strong><\/p>\n<p>In some high load situations, we need to find out the resource consumption of each user in the server to figure out the exact issue. There are a lot of options\/commands to find the same. Normally, we are using the \u201cps\u201d and \u201ctop\u201d command for performing this. Separating or sorting Unix user with their own resource usage is quit hard with a Linux beginner. &nbsp;The command PS has a lot of switches for sorting processes in different manner. We can simply sort the current executing processes with its CPU and Memory conception ratio. Also, here is a simple link&nbsp;for monitoring your server load \u201cLoad monitoring in Linux servers\u201c<\/p>\n<p>\u201cps command\u201d and \u201ctop command\u201d have a lot of options, here I am explaining some useful command combinations to find the resource(cpu, memory\u2026) usages of users in the server.<\/p>\n<p>It\u2019s simply a static output of current resource usage in the server. You can use the grep command to separate users.<\/p>\n<p><strong>To list top 10 CPU usage processes with user<\/strong><\/p>\n<pre># ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>[root@Coimbatorewebhosting~]# ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10\r\n%CPU   PID    USER     COMMAND\r\n 0.0     9    root     [rcu_sched]\r\n 0.0  9202    vnstat   \/usr\/sbin\/vnstatd -n\r\n 0.0     8    root     [rcu_bh]\r\n 0.0  8907    root     [kworker\/u4:2]\r\n 0.0     7    root     [migration\/0]\r\n 0.0   749    postfix  qmgr -l -t unix -u\r\n 0.0   746    root     \/usr\/libexec\/postfix\/master -w\r\n 0.0    68    root     [deferwq]\r\n 0.0     5    root     [kworker\/0:0H]\r\n[root@Coimbatorewebhosting~]#\r\n<\/pre>\n<p><strong>Find out top 10 CPU consuming process<\/strong><\/p>\n<pre># ps -auxf|sort -nr -k3|head -10<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>[root@Coimbatorewebhosting~]# ps -auxf|sort -nr -k3|head -10\r\nvnstat    9202  0.0  0.0   7444   848 ?        Ss   Feb19   0:48 \/usr\/sbin\/vnstatd -n\r\nUSER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND\r\nroot         9  0.0  0.0      0     0 ?        S    Feb19   3:56  \\_ [rcu_sched]\r\nroot      8907  0.0  0.0      0     0 ?        S    Feb19   0:00  \\_ [kworker\/u4:2]\r\nroot         8  0.0  0.0      0     0 ?        S    Feb19   0:00  \\_ [rcu_bh]\r\nroot       746  0.0  0.2  89036  2172 ?        Ss   Feb19   0:04 \/usr\/libexec\/postfix\/master -w\r\nroot         7  0.0  0.0      0     0 ?        S    Feb19   0:00  \\_ [migration\/0]\r\nroot        68  0.0  0.0      0     0 ?        S&lt;   Feb19   0:00  \\_ [deferwq]\r\nroot         5  0.0  0.0      0     0 ?        S&lt;   Feb19   0:00  \\_ [kworker\/0:0H]\r\nroot       494  0.0  0.0 110036   844 tty1     Ss+  Feb19   0:00 \/sbin\/agetty --noclear tty1 linux\r\n[root@Coimbatorewebhosting~]#<\/pre>\n<p><strong>To list top 10 Memory consuming processes with user<\/strong><\/p>\n<pre># ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>[root@Coimbatorewebhosting~]# ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10\r\n 1.6   450 root     \/usr\/bin\/python -Es \/usr\/sbin\/tuned -l -P\r\n 1.3 19168 root     \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.8   457 polkitd  \/usr\/lib\/polkit-1\/polkitd --no-debug\r\n 0.7 23926 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23925 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23924 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23424 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23388 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23387 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n 0.7 23386 apache   \/usr\/sbin\/httpd -DFOREGROUND\r\n[root@Coimbatorewebhosting~]#\r\n<\/pre>\n<p><strong>Find out the top 10 memory consuming process<\/strong><\/p>\n<pre># ps -auxf|sort -nr -k4|head -10<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>[root@Coimbatorewebhosting~]# ps -auxf|sort -nr -k4|head -10\r\nroot       450  0.0  1.6 553152 16436 ?        Ssl  Feb19   2:12 \/usr\/bin\/python -Es \/usr\/sbin\/tuned -l -P\r\nroot     19168  0.0  1.3 330364 13248 ?        Ss   Feb19   1:01 \/usr\/sbin\/httpd -DFOREGROUND\r\npolkitd    457  0.0  0.8 528308  8844 ?        Ssl  Feb19   0:00 \/usr\/lib\/polkit-1\/polkitd --no-debug\r\napache   23926  0.0  0.7 330364  7784 ?        S    Feb26   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23925  0.0  0.7 330364  7784 ?        S    Feb26   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23924  0.0  0.7 330364  7788 ?        S    Feb26   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23424  0.0  0.7 330364  7772 ?        S    Feb25   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23388  0.0  0.7 330364  7788 ?        S    Feb25   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23387  0.0  0.7 330364  7788 ?        S    Feb25   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\napache   23386  0.0  0.7 330364  7768 ?        S    Feb25   0:00  \\_ \/usr\/sbin\/httpd -DFOREGROUND\r\n[root@Coimbatorewebhosting~]#\r\n<\/pre>\n<p><strong>Find out every process running under a user<\/strong><\/p>\n<pre># ps -U user-name -u user-name u<\/pre>\n<p>Or<\/p>\n<pre># ps -e -o pid,user,args|grep $username<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>[root@Coimbatorewebhosting~]# ps -e -o pid,user,args|grep root\r\n    1 root     \/usr\/lib\/systemd\/systemd --switched-root --system --deserialize 21\r\n    2 root     [kthreadd]\r\n    3 root     [ksoftirqd\/0]\r\n    5 root     [kworker\/0:0H]\r\n    7 root     [migration\/0]\r\n    8 root     [rcu_bh]\r\n    9 root     [rcu_sched]\r\n   10 root     [watchdog\/0]\r\n   11 root     [watchdog\/1]\r\n   12 root     [migration\/1]\r\n   13 root     [ksoftirqd\/1]\r\n   15 root     [kworker\/1:0H]\r\n   17 root     [kdevtmpfs]\r\n   18 root     [netns]\r\n<\/pre>\n<p>To get a dynamic result you must use the \u2018top\u2018 command instead of \u2018ps\u2019 or use the \u2018watch\u2018 command along with the \u2018ps\u2019.<\/p>\n<p><strong>To show the process usage of a user with \u2018top\u2019<\/strong><\/p>\n<pre># top -u $username<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>top - 11:47:03 up 7 days, 23:53,  2 users,  load average: 0.00, 0.01, 0.05\r\nTasks:  76 total,   2 running,  74 sleeping,   0 stopped,   0 zombie\r\n%Cpu(s):  0.0 us,  0.2 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st\r\nKiB Mem :  1012436 total,   370668 free,    68052 used,   573716 buff\/cache\r\nKiB Swap:  2097148 total,  2097148 free,        0 used.   906684 avail Mem\r\n\r\n  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND\r\n23384 apache    20   0  330364   7768   1936 S   0.0  0.8   0:00.00 httpd\r\n23385 apache    20   0  330364   7788   1932 S   0.0  0.8   0:00.00 httpd\r\n23386 apache    20   0  330364   7768   1936 S   0.0  0.8   0:00.00 httpd\r\n23387 apache    20   0  330364   7788   1932 S   0.0  0.8   0:00.00 httpd\r\n23388 apache    20   0  330364   7788   1936 S   0.0  0.8   0:00.00 httpd\r\n23424 apache    20   0  330364   7772   1936 S   0.0  0.8   0:00.00 httpd\r\n23924 apache    20   0  330364   7788   1936 S   0.0  0.8   0:00.00 httpd\r\n23925 apache    20   0  330364   7784   1932 S   0.0  0.8   0:00.00 httpd\r\n23926 apache    20   0  330364   7784   1932 S   0.0  0.8   0:00.00 httpd\r\n<\/pre>\n<p>You can refer this \u201cHow to show process usage for single user with TOP command\u201d for more details<\/p>\n<p><strong>To list top 10 CPU usage processes with user<\/strong><\/p>\n<pre># watch \"ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10\"<\/pre>\n<p><span style=\"text-decoration: underline;\"><strong>Output<\/strong><\/span><\/p>\n<pre>0.4 24497 root     watch ps -e -o pcpu,pid,user,args|sort -k1 -nr|head -10\r\n%CPU   PID USER     COMMAND\r\n 0.0     9 root     [rcu_sched]\r\n 0.0  9202 vnstat   \/usr\/sbin\/vnstatd -n\r\n 0.0     8 root     [rcu_bh]\r\n 0.0  8907 root     [kworker\/u4:2]\r\n 0.0     7 root     [migration\/0]\r\n 0.0   749 postfix  qmgr -l -t unix -u\r\n 0.0   746 root     \/usr\/libexec\/postfix\/master -w\r\n 0.0    68 root     [deferwq]\r\n<\/pre>\n<p><strong>To list top 10 Memory consuming processes with user<\/strong><\/p>\n<pre># watch \"ps -e -o pmem,pid,user,args|sort -k1 -nr|head -10\"<\/pre>\n<p>instead you can use the grep command to separate users.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find out the resource(cpu, memory) usages of users In some high load situations, we need to find out the resource consumption of each user in the server to figure out the exact issue. There are a lot of options\/commands to find the same. Normally, we are using the \u201cps\u201d and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":928,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[51,52,53],"class_list":["post-913","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-latest","tag-cpu-consuming-process","tag-memory-consuming","tag-top-10-memory"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/04\/Find-out-why-300x287.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-eJ","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/928"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}