Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically I need to make a bash script that acts as a handy tool for diagnosing performance issues. The script needs to first determine each unique process owner on the system, and then for each user that has current processes on the system it needs to:

  • Determine the number of processes owned by that user
  • Determine the sum of memory for all processes owned by that user (SZ)
  • Determine the sum of the current CPU usage for all processes owned by that user (C)
  • Determine the cumulative time (TIME) and process name (CMD) of the process with the highest cumulative time owned by that user (Hog: process)

I guess the first step would be to determine all of the unique process owners on the system, and then loop through each?

share|improve this question

If you want to have a quick look at processes, use top and read the man page to learn how to sort by various columns

To find (most of) the information you want:

ps ax -o user,sz,pcpu | 
awk '
    NR>1 {n[$1]++; sz[$1]+=$2; cpu[$1]+=$3}
    END {
        for (user in n) 
            printf "%-8s  %4d  %12d  %.1f\n", user, n[user], sz[user], cpu[user]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.