我正在尝试获取进程的最后一个pid(例如sleep)。我这样做:最后一个pid进程linux
# sleep 10 &
[1] 14115
但是,当我使用这个命令来获得最后的PID:
# ps aux --sort +start_time | tail -n 4 | awk 'NR==1{print $2 " " $11}'
14125 sleep
pid是不一样的,我不明白我在做什么错的,因为如果我这样做,但没有命令的最后一部分,我会得到相同的PID:
# sleep 10 &
[1] 15853
# ps aux --sort +start_time | tail -n 4
root 15853 0.0 0.1 3364 520 pts/2 S 16:45 0:00 sleep 10
www-data 15871 0.0 0.0 1864 452 ? S 16:45 0:00 sleep 1
root 15872 0.0 0.2 4344 1168 pts/2 R+ 16:45 0:00 ps aux --sort +start_time
root 15873 0.0 0.1 3756 676 pts/2 S+ 16:45 0:00 tail -n 4
在此先感谢
[解决]
# ps aux --sort +start_time | tail -n 5 | awk 'NR==1{print $2 " " $11}'
为awk
过程开始的具体的处理
# pgrep -n 'name_of_the_process'
我用尾巴-n5知道了,谢谢! :) – Safira