0

from ps ax we get the following output

 ps ax
   PID TTY      STAT   TIME COMMAND
     1 ?        Rs   611:56 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
     2 ?        S      4:46 [kthreadd]
     3 ?        R    3499:33 [ksoftirqd/0]
     5 ?        S<     0:00 [kworker/0:0H]
     7 ?        S     16:24 [migration/0]
     8 ?        S      0:00 [rcu_bh]
     9 ?        S      0:00 [rcuob/0]
    10 ?        S      0:00 [rcuob/1]
    11 ?        S      0:00 [rcuob/2]
    12 ?        S      0:00 [rcuob/3]
    13 ?        S      0:00 [rcuob/4]
    14 ?        S      0:00 [rcuob/5]
    15 ?        S      0:00 [rcuob/6]
    16 ?        S      0:00 [rcuob/7]
    17 ?        S      0:00 [rcuob/8]
    18 ?        S      0:00 [rcuob/9]
    19 ?        S      0:00 [rcuob/10]

so we want to capture the R on the third field for example

 ps ax | awk '$3 ~ /R/ { print }'
   139 ?        R    1935:31 [rcuos/1]

now we want both , to capture R and D on the third field

in this case what should be the syntax in order to capture ether R or D on the third field ?

  • 2
    The regex /R|D/. – jordanm Mar 25 at 14:04
  • 1
    or /[RD]/ as well. – glenn jackman Mar 25 at 14:07
7

either

ps -ax | awk '$3 ~ /R|D/ '

or

ps -ax | awk '$3 == "R" || $3 == "D" '

note that implicit action is print


you can use o option in ps to change or select field you need

ps -a -o stat,pid,args | awk '$1 ~ /[DR]/ { $1="" ; print } '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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