LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-12-2020, 07:39 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
is there a way to show top summarized by user?


i would like to see a display like top that shows a summary by user with one line per user and the heavier users on top. for each user this would have the sum of all processes by that user. is there some kind of configuration (i didn't a simple direct option in the man page) for top or some alternate software to do this?
 
Old 07-12-2020, 09:52 PM   #2
eight.bit.al
Member
 
Registered: Jul 2015
Location: Prison
Distribution: a new distro every day
Posts: 124

Rep: Reputation: Disabled
A quick search found:

run either top -u {userName} or htop -u {userName} commands in a terminal.
Not exactly what you wanted.

8bit
 
Old 07-12-2020, 10:12 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,321
Blog Entries: 28

Rep: Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141Reputation: 6141
I also looked into this and found what eight.bit.al found, a way to show output per user. I could not find a way to sort output by user.

It occurs to me that there might be a way to pipe the output of top to a script that in turn would then sort the output by user and store it in a file, but that would be only a snapshot, not a dynamic representation.

Sadly, I would be woefully unqualified to produce such a script.

Last edited by frankbell; 07-12-2020 at 10:17 PM.
 
1 members found this post helpful.
Old 07-12-2020, 11:26 PM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
top has an excellent manual page. It also has a nice (in my opinion) help facility; just type h while it's running.

Section 3b of the man page tells you how to display any field you can dream for, including the user ID, and how to sort by any field.

I haven't checked whether you can then summarize by user.
 
Old 07-13-2020, 05:55 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
just to be clear, i don't want to pick one user and show just that user's processes. i want to see which user is using the most resource.

a program that does this would get all the same data that top does, then collect a list of all the users. it would make an array with rows just like it did for processes. the it would loop through the array of processes, find the row for its real user in the user array, and add the resources to that row. the PID field would just be incremented by one to count how many active processes that user has. once all that is done, then sort the user array as appropriate and display it instead of the process array.

yeah, maybe i should get the source for top, add this code, add an option to engage this, and release the patch.
 
Old 07-13-2020, 06:39 PM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Skaperen View Post
a program that does this would get all the same data that top does, then collect a list of all the users. it would make an array with rows just like it did for processes. the it would loop through the array of processes, find the row for its real user in the user array, and add the resources to that row. the PID field would just be incremented by one to count how many active processes that user has. once all that is done, then sort the user array as appropriate and display it instead of the process array.
awk is great at summarizing data like this. Since the structure of top's output lines is quite regular, it could serve as convenient input for a simple awk script.

Even more convenient might be the original data source under /proc, in particular values like /proc/PID/stat or /proc/PID/io. See the manual page.
 
Old 07-14-2020, 11:34 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,790

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Here is a part of a script that I once wrote:
Code:
#!/bin/sh

PATH=/usr/xpg4/bin:/usr/bin:/bin:/usr/sbin:/usr/ucb
export PATH
set -f
# secure GNU grep
unset GREP_OPTIONS

if [ -f /proc/cpuinfo ]; then
 scaleps=`grep -c '^processor' /proc/cpuinfo` # ps pcpu is per vcpu
else
 scaleps=1 # ps pcpu is per total
fi

#all in one variable:
allprocs=`ps -e -o pcpu= -o vsz= -o rss= -o user=`
#user= must be last in ps to not be truncated

#assume 900 processes maximum:
echo "#procs per user, top 3:"
echo "$allprocs" |
 awk '{s[$4]++} END {for(i in s) printf " %-10s %-4d , %2d %%\n",i,s[i],int(s[i]*100/900)}' |
 sort -nr -k 2,2 | head -3
#assume 6000 threads maximum:
echo "#threads per user, top 3:"
ps -Le -o user= |
 awk '{s[$1]++} END {for(i in s) printf " %-9s %-4d , %2d %%\n",i,s[i],int(s[i]*100/6000)}' |
 sort -nr -k 2,2 | head -3
echo "#cpu% per user, top 3:"
echo "$allprocs" |
 awk '{s[$4]+=$1} END {for(i in s) printf " %-9s %2.1f\n",i,s[i]/c}' c=$scaleps |
 sort -nr -k 2,2 | head -3
echo "#vmemoryMB per user, top 3:"
echo "$allprocs" |
 awk '{s[$4]+=$2} END {for(i in s) printf " %-9s %4.1f\n",i,s[i]/1024}' |
 sort -nr -k 2,2 | head -3
echo "#residentMB per user, top 3:"
echo "$allprocs" |
 awk '{s[$4]+=$3} END {for(i in s) printf " %-9s %4.1f\n",i,s[i]/1024}' |
 sort -nr -k 2,2 | head -3
 
Old 07-15-2020, 10:06 PM   #8
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
i still want to have it in a display just like top itself does.
 
Old 07-16-2020, 04:00 AM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Try atop. The key u gives summaries by user.

Last edited by shruggy; 07-18-2020 at 06:20 AM.
 
2 members found this post helpful.
Old 07-18-2020, 12:36 AM   #10
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
atop is just what i was looking for. i am using the -u command line option.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Is there a way to show only ACTUAL normal mounted devices? Lot of distros seem to put lot of stuff in there Red Squirrel Linux - Software 14 05-25-2020 02:16 AM
[SOLVED] Is there a way to quickly show or hide all windows in Fluxbox? linustalman Linux - Desktop 2 07-30-2018 07:02 AM
Is there a way to show the output of background process? nadavvin Linux - General 1 05-27-2007 11:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration