1. PS命令进程开始时间算法
1.1. 算法逻辑:
ps中获取的进程开启时间是系统开机时间加上进程启动时系统已经运行的时间。
在man ps手册中指明ps获取进程的信息是通过/proc中文件获取的。
NOTES
This ps works by reading the virtual files in /proc. This ps does not need to be setuid kmem or have any privileges to run. Do not give this ps any special
permissions.
随机找一个 运行 中的进程cron_monitor.pl
[root@TENCENT64_site /proc]# ps -p 6287 -o pid,lstart,cmd
PID STARTED CMD
6287 Mon Mar 14 12:27:38 2016 /usr/bin/perl /usr/local/ieod-public/cron_monitor/bin/cron_monitor.pl
进程开始时系统已经运行的时间
[root@TENCENT64_site /proc/6287]# cat /proc/6287/stat
6287 (perl) S 1 5942 5942 0 -1 4202496 34474695 1048743185 0 0 5721 14989 9571 59080 20 0 1 0 26528875 32456704 1070 18446744073709551615 4194304 4198628 140735995564832 140735995563736 139932155378208 0 0 134 0 18446744071579238039 0 0 17 4 0 0 289 0 0
系统开机后到该进程开启时CPU跳动的次数
[root@TENCENT64_site /proc/6287]# cat /proc/6287/stat |awk '{print $22}'
26528875
系统开机时Unix时间戳
[root@TENCENT64_site /proc/6287]# cat /proc/stat |grep btime
btime 1457664370
硬件主频HZ
[root@TENCENT64_site /proc/6287]# getconf CLK_TCK
100
进程开启时间 计算
[root@TENCENT64_site /proc/6287]# echo 1457664370 + 26528875/100 |bc
1457929658
[root@TENCENT64_site /proc/6287]# date -d "1970-01-01 UTC 1457929658 seconds"
Mon Mar 14 12:27:38 CST 2016
1.2. 参考
http://www.hehehehehe.cn/i/825.html http://blog.csdn.net/zhangxinrun/article/details/5587098