Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.