+2 votes
in Operating Systems by (73.8k points)

When I run ps aux command, I see the list of processes unsorted. How can I sort them by start time?

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  37988  6004 ?        Ss   Apr10   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Apr10   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Apr10   0:02 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Apr10   0:00 [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    Apr10   0:04 [rcu_sched]
root         8  0.0  0.0      0     0 ?        S    Apr10   0:00 [rcu_bh]
root         9  0.0  0.0      0     0 ?        S    Apr10   0:05 [migration/0]
 

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

Use 'ps aux --sort=start' or 'ps aux --sort=lstart' to sort the processes by start time. The time will not show seconds.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

group7   27585  0.0  0.0   4504   692 pts/2    T    00:20   0:00 sh -c (cat /home/moderator/pipes/sto12D/sto12)2>/dev/null

group7   27586  0.0  0.0   4296   272 pts/2    T    00:20   0:00 cat /home/moderator/pipes/sto12D/sto12

group7   27587  0.0  0.0  23232  3828 pts/2    T    00:20   0:00 nano communication.py

group7   27693  0.0  0.0  23100  3740 pts/2    T    00:21   0:00 nano client.py

cs544    28386  0.0  0.0   8092   828 pts/0    T    00:54   0:00 cat -v /dev/random

root     28701  0.0  0.0      0     0 ?        S    00:57   0:00 [kworker/0:1]

root     28738  0.0  0.0  52284  3488 pts/0    S    01:00   0:00 su - moderator

moderat+ 28739  0.0  0.1  22576  5252 pts/0    S+   01:00   0:00 -su

root     28999  0.0  0.1  92828  6964 ?        Ss   01:05   0:00 sshd: group14 [priv]

group14  29001  0.0  0.1  45276  4596 ?        Ss   01:05   0:00 /lib/systemd/systemd --user

group14  29002  0.0  0.0  61440  2108 ?        S    01:05   0:00 (sd-pam)

group14  29058  0.0  0.0  92828  3392 ?        S    01:05   0:00 sshd: group14@pts/4

group14  29059  0.0  0.1  22576  5304 pts/4    Ss   01:05   0:00 -bash

If you want to see the second of the start time of a process, use 'ps -o lstart= -p PID' or 'stat /proc/PID | grep Change'

group12@CS544Server:~$ ps -o lstart= -p 30705

Fri Apr 13 01:42:15 2018

group12@CS544Server:~$ stat /proc/30705 | grep Change

Change: 2018-04-13 01:42:44.741417457 -0600

by (71.8k points)
'ps aux --sort=start_time' can also be used. It will put sort the processes in ascending order of the start_time. To sort in descending order use 'ps aux --sort=-start'.

...