3

I am trying to pipe the output of ps -ax -o pid,lstart into an awk and work with that or try to sort by a certain column using sort.

The output of ps -ax -o pid,lstart is something like:

       PID         STARTED
    1 Tue Feb  4 23:10:00 2020
    2 Tue Feb  4 23:10:00 2020
    3 Tue Feb  4 23:10:00 2020
    4 Tue Feb  4 23:10:00 2020
    6 Tue Feb  4 23:10:00 2020
    8 Tue Feb  4 23:10:00 2020
    9 Tue Feb  4 23:10:00 2020
   10 Tue Feb  4 23:10:00 2020
   11 Tue Feb  4 23:10:00 2020
   12 Tue Feb  4 23:10:00 2020
   14 Tue Feb  4 23:10:00 2020
   15 Tue Feb  4 23:10:00 2020
   16 Tue Feb  4 23:10:00 2020
   17 Tue Feb  4 23:10:00 2020
   18 Tue Feb  4 23:10:00 2020
   20 Tue Feb  4 23:10:00 2020

Which makes the job much more difficult because I'd have to sort by day first, then an hour, minute, and second...

2

1 Answer 1

3

Similar to this related answer

you could use etimes as a proxy for lstart giving you a value in seconds that permits a simple numeric sort ex.

$ ps -eoetimes=,pid=,lstart= | sort -rnk1,1 | tail -10
    824 13816 Thu Feb  6 08:23:48 2020
    595 13851 Thu Feb  6 08:27:37 2020
    563 13865 Thu Feb  6 08:28:09 2020
    502 13882 Thu Feb  6 08:29:10 2020
    443 13896 Thu Feb  6 08:30:09 2020
     83 13965 Thu Feb  6 08:36:09 2020
     70 13966 Thu Feb  6 08:36:22 2020
      0 13983 Thu Feb  6 08:37:32 2020
      0 13982 Thu Feb  6 08:37:32 2020
      0 13981 Thu Feb  6 08:37:32 2020

From man ps:

   etimes      ELAPSED   elapsed time since the process was started, in
                         seconds.

   lstart      STARTED   time the command started.  See also
                         bsdstart, start, start_time, and stime.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .