Any way to sort ps output based on STIME?

Hi,

This is one of the thing that am looking for when I post the question on the ps wrapper. It has since been closed as it has taken me too long to post an example.

I have replaced some of the original content of the ps output.

uname -a = SunOS <hostname> 5.11 11.3 sun4v sparc sun4v

= This is the current output

$: ps -ef | grep pmon | grep -i abc | grep -v grep

     UID   PID  PPID   C    STIME TTY         TIME CMD
  oracle 27452 16899   0   Sep 15 ?           5:42 ora_pmon_abcd9
  oracle  9843 16899   0   Sep 15 ?           4:50 ora_pmon_abcd11
  oracle 28017 16899   0   Sep 26 ?           0:38 ora_pmon_abcd15
  oracle  6017 16899   0   Sep 15 ?           6:37 ora_pmon_abcd1
  oracle  8273 16899   0   Sep 15 ?           4:22 ora_pmon_abcd10
  oracle 29331 16899   0   Sep 15 ?           5:36 ora_pmon_abct1
  oracle  4154 16899   0   Sep 15 ?           4:33 ora_pmon_abct3
  oracle 24750 16899   0   Sep 15 ?           4:33 ora_pmon_abcd8
  oracle  5755 16899   0 06:28:27 ?           0:08 ora_pmon_abcd2
  oracle 23611 16899   0   Sep 15 ?           5:42 ora_pmon_abcd5
  oracle 27760 16899   0   Sep 21 ?           2:46 ora_pmon_abct11
  oracle 22935 16899   0   Sep 15 ?           5:17 ora_pmon_abcd3

= This is the current output that I am hoping to have. I just sorted the output manually below

     UID   PID  PPID   C    STIME TTY         TIME CMD
  oracle  8273 16899   0   Sep 15 ?           4:22 ora_pmon_abcd10
  oracle  4154 16899   0   Sep 15 ?           4:33 ora_pmon_abct3
  oracle 24750 16899   0   Sep 15 ?           4:33 ora_pmon_abcd8
  oracle  9843 16899   0   Sep 15 ?           4:50 ora_pmon_abcd11
  oracle 22935 16899   0   Sep 15 ?           5:17 ora_pmon_abcd3  
  oracle 29331 16899   0   Sep 15 ?           5:36 ora_pmon_abct1
  oracle 23611 16899   0   Sep 15 ?           5:42 ora_pmon_abcd5
  oracle 27452 16899   0   Sep 15 ?           5:42 ora_pmon_abcd9
  oracle  6017 16899   0   Sep 15 ?           6:37 ora_pmon_abcd1
  oracle 27760 16899   0   Sep 21 ?           2:46 ora_pmon_abct11
  oracle 28017 16899   0   Sep 26 ?           0:38 ora_pmon_abcd15
  oracle  5755 16899   0 06:28:27 ?           0:08 ora_pmon_abcd2

Can't find the right ps args to use. Not sure if there is one available tbh. Any way, hope I can get some suggestion on how to achieve the desired output that am after.

Thanks in advance.

1 Like

You can do the following to sort based on column number, than sort the output based on column numerically.

sort -k5 | sort -nr

The whole thing would look something of the like

ps ef | grep blah | grep -i blah | grep -v grep | sort -k <stime column number> | sort -nr