Viewing Processes with the prstat command

The prstat command displays information about the processes similar to that displayed by the ps and pgrep commands. However, a unique feature of the prstat command is that it refreshes (updates) the output in a periodic fashion. You can determine the frequency of updates.

The prstat command has the following syntax:

prstat [<options>] [<interval> [<count>] ]

The <interval> argument specifies the time lapse between two consecutive display updates, and the default is five seconds. The <count> argument specifies how many times the display will be updated in total, and the default is infinity—that is, until the command process is terminated. Some values of <options> for this command are described here:

  • -a Display information about processes and users.
  • -c Display new reports below the previous displays instead of overwriting them.
  • -n <number< Display information about only the first x number of selected processes where the value of x is specified by <number>.
  • -p <pidList> Display information about only those processes whose process ID is in the list specified by <pidList>.
  • -s <key>. Sort output lines by the field specified by <key> in descending order. Only one key can be used as an argument. The key has five possible values:
    • cpu Sort by CPU usage by the process. This is the default.
    • pri Sort by the process priority.
    • rss Sort by resident set size.
    • size Sort by size of process image.
    • time Sort by the process execution time.
  • -S <key> Sort output lines by the field specified by <key> in descending order.
  • -u <euiList> Select only those processes whose effective user ID is in the list specified by <euiList>.
  • -U <uidList> Select only those processes whose real user ID is in the list specified by <uidList>.

You may be wondering at this point how you are going to remember all these options for these commands. Well, note that some options are related to the properties of a process and are repeated for more than one command. Those options along with the process properties they are related to are described in the following table:

OptionProcess propertyDescription
-p Process ID The unique identifier for a process
-u Effective user ID The user ID whose permissions are being used by the process
-U Real user ID The user ID for the user that started the process
-g Effective group ID The group ID for the group whose group permissions are being used by the process
-G Real group ID The group ID of the group that owns the process

To understand the difference between real and effective, suppose a user mchurchi starts a process passwd that is owned by the user root. The executable passwd has its setuid and setgid bits set—that is, its permission mode is 6555. Therefore, although mchurchi started the process passwd, it's running with privileges associated with the root. In this case, mchurchi is called the real user of this process, and root is called the effective user. Accordingly mchurchi's user ID is the real user ID for the process, and root's user ID is the effective user ID for the process.