Everything Penguin

Focusing on Linux-based Operating Systems
htDig Search:

Operating Systems
  • /pub/OS/Linux

  • Storage
  • File Systems
  • HPC
  • /pub/Storage

  • Networking
  • /pub/Networking

  • Network Services
  • /pub/NetworkServices

  • Security
  • /pub/Security
  • Keytool/OpenSSL

  • Clustering
  • HA
  • DRM

  • Development
  • Design
  • C/C++
  • Java
  • Perl
  • Python
  • Shell
  • Web / J2EE

  • Not Linux ?
  • BSD
  • HP-UX
  • Mac
  • Solaris
  • VM
  • Windows
  • /pub/OS

  • Other
  • /pub
  • /pub/3rdParty
  •  Parent Directory

    Linux Priorities && the 'ps' Command
    Brett Lee
    =========================================
    
    The 'ps' command is one of the Linux Swiss army knives.  Versatile, powerful,
    and probably under-utilized.  That said, here's just a small bit of what can
    be done.
    
    ~> ps -elcy | head
    S   UID   PID  PPID CLS PRI   RSS    SZ WCHAN  TTY          TIME CMD
    S     0     1     0 TS   23   312   199 -      ?        00:00:04 init
    S     0     2     1 FF  139     0     0 migrat ?        00:00:00 migration/0
    
    S       State (D, R, S, T, W, X, Z)  - Typically "R" and "S"
            D   Uninterruptible sleep (usually IO)
            R   Running or runnable (on run queue)
            S   Interruptible sleep (waiting for an event to complete)
            T   Stopped, either by a job control signal or because it is being traced.
            W   paging (not valid since the 2.6.xx kernel)
            X   dead (should never be seen)
            Z   Defunct ("zombie") process, terminated but not reaped by its parent.
    UID     User ID
    PID     Process ID
    PPID    Parent Process ID
    CLS     Class: TS=Time Sharing (SCHED_OTHER), FF=SCHED_FIFO, RR=SCHED_RR
    PRI     Priority.  TS=0-39.  FF=139.  WTF?  See below.
    RSS     Resident Set Size
    SZ      Estimated Size of Swap if... (ignore)
    WCHAN   Name of Kernel Function in which the Process is Sleeping.
            A "-" is Running.  A "*" is Thread, but info is not displayed.
    TTY     Controlling Terminal.
    TIME    Cumulative CPU Time in "[dd-]hh:mm:ss" format
    CMD     Command
    
    
    Understanding the PRI value from the display is certainly not intuitive.  How
    could a real time (FF) process be running with a 139 priority and a TS process
    run with a 23 priority?
    
    
    
    Maybe this will help:
    
    ~> ps -el
    F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
    4 S     0     1     0  0  76   0 -   199 -      ?        00:00:04 init
    1 S     0     2     1  0 -40   - -     0 migrat ?        00:00:00 migration/0
    
    Looking at the PRI and NIce fields, that doesn't help at all!  In fact it
    makes things worse!! Now we have the TS task running at a PRI of 76 with a
    NIce value of 0, and the FF task running with a priority of -40.  WTF?
    
    
    
    
    
    Trying a custom ps:
    
    ~> ps -eo state,pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:20,comm
    S   PID   TID CLS RTPRIO  NI PRI PSR %CPU STAT WCHAN                COMMAND
    S     1     1 TS       -   0  23   4  0.0 S    -                    init
    S     2     2 FF      99   - 139   0  0.0 S    migration_thread     migration/0
    
    
    Aha!  There are two priority fields, RTPRIO and PRI.  Makes sense, as there
    are a different scheduling classes.  Even better, the real time jobs all show
    as 139 priority, which seems fine as they are not scheduled in that class;
    they are scheduled in the RTPRIO class.  An jobs not scheduled in the RTPRIO
    class all show PRI values that make sense, being in the 0 (100) to 40 (140)
    range.
    
    
    
    
    Can't remember the options?  Me either.  Consider adding this function
    to your startup script (.bashrc):
    
    # Different ps outputs
    #
    ps() {
      case ${1} in
    
        tree )
          /bin/ps --forest -eaf
          ;;
        wtree )
          /bin/ps -eflH
          ;;
        stat )
          /bin/ps faux
          ;;
        pri )
          /bin/ps -eo state,pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:20,comm
          ;;
    
        * )
          /bin/ps ${*}
          ;;
      esac
    }
    

    Other Sites

    RFC's
  • FAQ's
  • IETF
  • RFC Sourcebook

  • Linux
  • Linux - Intro
  • Linux Kernel
  • Linux Kernel (LKML)
  • Bash - Intro
  • Bash - Advanced
  • Command Line
  • System Administration
  • Network Administration
  • Man Pages (& more)
  • More Guides
  • Red Hat Manuals
  • HOWTO's

  • Reference/Tutorials
  • C++ @ cppreference
  • C++ @ cplusplus
  • CSS @ echoecho
  • DNS @ Zytrax
  • HTML @ W3 Schools
  • Java @ Sun
  • LDAP @ Zytrax
  • Linux @ YoLinux
  • MySQL
  • NetFilter
  • Network Protocols
  • OpenLDAP
  • Quagga
  • Samba
  • Unix Programming



  • This site contains many of my notes from research into different aspects of the Linux kernel as well as some of the software provided by GNU and others. Thouugh these notes are not fully comprehensive or even completetly accurate, they are part of my on-going attempt to better understand this complex field. And, they are your to use.

    Should you wish to report any errors or suggestions, please let me know.

    Should you wish to make a donation for anything you may have learned here, please direct that donation to the ASPCA, with my sincere thanks.

    Brett Lee
    Everything Penguin

    The code for this site, which is just a few CGI scripts, may be found on GitHub (https://github.com/userbrett/cgindex).

    For both data encryption and password protection, try Personal Data Security (https://www.trustpds.com).


    "We left all that stuff out. If there's an error, we have this routine called 'panic', and when its called, the machine crashes, and you holler down the hall, 'Hey, reboot it.'"

        - Dennis Ritchie on Unix (vs Multics)


    Google
    [ Powered by Red Hat Linux ] [ Powered by Apache Server] [ Powered by MySQL ]

    [ Statistics by AWStats ]