我正在尝试将 的输出ps -ax -o pid,lstart
通过管道传输到awk
并使用它,或者尝试使用 按某一列进行排序sort
。
输出ps -ax -o pid,lstart
类似于:
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
这使得工作变得更加困难,因为我必须先按天排序,然后按小时、分钟和秒排序......
答案1
与此相关答案类似
您可以用它etimes
作为代理,以lstart
秒为单位给您一个允许简单数字排序的值。
$ 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
从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.