Linux ps 命令查看进程启动及运行时间
引言
同事问我怎样看一个进程的启动时间和运行时间,我第一反应当然是说用 ps 命令啦。ps aux或ps -ef不就可以看时间吗?
ps aux选项及输出说明
我们来重新复习下ps aux的选项,这是类 BSD 风格的命令选项,因为不带“-”。
通过 man 可以看到 aux 选项解释如下:
a Lift the BSD-style "only yourself" restriction, which is imposed upon the set of all processes
when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like.
The set of processes selected in this manner is in addition to the set of processes selected by other means.
An alternate description is that this option causes ps to list all processes with a terminal (tty),
or to list all processes when used together with the x option. x Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes
when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like.
The set of processes selected in this manner is in addition to the set of processes selected by other means.
An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps),
or to list all processes when used together with the a option. u Display user-oriented format.
然后再来看下ps aux的输出结果,其首行如下,说明了输出的各列:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
我们可以看到START和TIME列,通过 man 其说明如下:
bsdstart START time the command started.
If the process was started less than 24 hours ago, the output format is " HH:MM",
else it is " Mmm:SS" (where Mmm is the three letters of the month).
See also lstart, start, start_time, and stime. bsdtime TIME accumulated cpu time, user + system.
The display format is usually "MMM:SS",
but can be shifted to the right if the process used more than 999 minutes of cpu time.
START 是命令启动的时间,如果在 24 小时之内启动的,则输出格式为”HH:MM”(小时:分钟),
否则就是”Mmm:SS”(月份英语单词前 3 个字母:一月的第几号?[SS 这里面怎么理解?为什么有冒号呢?输出并没冒号]) 可以知道,这里并不能直接看出 24 小时之前启动的命令的精确启动时间。
TIME 是累积的 CPU 时间(user+system),显示格式通常是”MMM:SS”。(分钟:秒) 可以看出,这里并不是指从命令启动开始到现在所花的时间。
ps -ef选项及输出说明
带一个“-”为 UNIX 风格的命令选项。
-e Select all processes. Identical to -A. -f Do full-format listing.
This option can be combined with many other UNIX-style options to add additional columns.
It also causes the command arguments to be printed.
When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added.
See the c option, the format keyword args, and the format keyword comm. -o format User-defined format.
format is a single argument in the form of a blank-separated or comma-separated list,
which offers a way to specify individual output columns.
The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired.
If all column headers are empty (ps -o pid= -o comm=) then the header line will not be output.
Column width will increase as needed for wide headers;
this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm).
Explicit width control (ps opid,wchan:42,cmd) is offered too.
The behavior of ps -o pid=X,comm=Y varies with personality;
output may be one column named "X,comm=Y" or two columnsnamed "X" and "Y".
Use multiple -o options when in doubt.
Use the PS_FORMAT environment variable to specify a default as desired;
DefSysV and DefBSD are macros that may be used to choose the default UNIX or BSD columns.
然后再来看下ps -ef的输出结果,其首行如下,说明了输出的各列:
UID PID PPID C STIME TTY TIME CMD
我们可以看到 STIM E和 TIME 列,通过 man 其说明如下 (我这台服务器上 ps 版本为 procps-ng version 3.3.9,man 中找不到 STIME 的解释,通过观察输出,
我们可以推断这个 STIME 其实和前面 START 是一样的,指的是命令启动的时间,这里有这个说明):
TIME 列也和前面说的 TIME 列一样指的命令使用的累积 CPU 时间。
使用 ps 命令查看进程启动的精确时间和启动后所流逝的时间
回到引言中的问题,同事实际要问的是一个进程启动的精确时间和进程启动后所流逝的时间。
其实这 2 个时间也是可以通过 ps 命令输出的。 标识符如下:
lstart STARTED time the command started. See also bsdstart, start, start_time, and stime.
etime ELAPSED elapsed time since the process was started, in the form [[DD-]hh:]mm:ss.
例子:
查看 nginx 进程启动的精确时间和启动后所流逝的时间:
[root@iZ25p102vo3Z ~]# ps -eo pid,lstart,etime,cmd | grep nginx
16968 Fri Mar 4 16:04:27 2016 41-21:14:04 nginx: master process /usr/sbin/nginx
17826 Fri Mar 4 22:53:51 2016 41-14:24:40 nginx: worker process
18312 Fri Apr 15 13:18:31 2016 00:00 grep --color=auto nginx
Linux ps 命令查看进程启动及运行时间的更多相关文章
- 查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊
1.查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊 2.Tomcat服务器和虚拟机的关系,Tomcat启动运行过程要调用系统环境变量的java_home啊,J ...
- ps命令查看进程指定项目信息、用户名过长显示UID
有次一个在使用ps命令时,发现部分用户显示的是用户名,有些用户显示的是UID,那是因为用户名长度超过8位的:也就是说ps命令用户名列默认只能显示8位(含8位)的用户名,超过8位就显示UID,如何让长度 ...
- 00014 - linux中用top、ps命令查看进程中的线程
在Linux上显示某个进程的线程的几种方式. 方法一:PS 在ps命令中,“-T”选项可以开启线程查看.下面的命令列出了由进程号为<pid>的进程创建的所有线程. 1.$ ps -T -p ...
- Linux常用命令 查看进程信息时 copy的-----温故而知新
1.查进程 ps命令查找与进程相关的PID号: ps a 显示现行终端机下的所有程序,包括其他用户的程序. ps -A 显示所有程序. ps c 列出程序时,显示每个程序真正的 ...
- Linux基础命令——查看进程命令
linux是一个 多进程 多用户的操作系统 ps(显示当前进程的状态) ps -ef 查看当前linux 进程 ps -ef | grep 'mysqld' 过滤mysql的进程 (grep ...
- linux ps 命令查看进程状态
显示其他用户启动的进程(a) 查看系统中属于自己的进程(x) 启动这个进程的用户和它启动的时间(u) 使用“date -s”命令来修改系统时间 比如将系统时间设定成1996年6月10日的命令如下. # ...
- linux ps命令查看最消耗CPU、内存的进程
1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10个进程 ps auxw|head -1;ps a ...
- Android中使用ps命令查看进程PID
adb shell "ps | grep com.sina.weibo" 这个命令可以看到微博的应用线程信息. PID:进程号 PPID:父进程号 VSIZE:进程的虚拟内存大小 ...
- linux ps命令,查看进程cpu和内存占用率排序(转)
使用以下命令查看: ps -aux | sort -k4,4n ps auxw --sort=rss ps auxw --sort=%cpu linux 下的ps命令 %CPU 进程的cpu占用率 % ...
随机推荐
- hihoCoder [Offer收割]编程练习赛83 D 生成树问题
题目 从 Kruskal 算法的角度来思考这个问题. 考虑 $n$ 个点的"空图"(即没有边的图). 先将 $m_2$ 条无权值的边加到图中,得到一个森林. 按边权从小到大的顺序枚 ...
- BZOJ 4827 [Hnoi2017]礼物 ——FFT
题目上要求一个循环卷积的最小值,直接破环成链然后FFT就可以了. 然后考虑计算的式子,可以分成两个部分分开计算. 前半部分FFT,后半部分扫一遍. #include <map> #incl ...
- bzoj 4196 树链剖分 模板
[Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2135 Solved: 1232[Submit][Status][D ...
- UVa 11234 The Largest Clique
找最长的连接的点的数量.用tarjan缩点,思考可知每一个强连通分量里的点要么都选,要么都不选(走别的路),可以动规解决. #include<iostream> #include<c ...
- hdu 3518 Boring counting 后缀数组 height分组
题目链接 题意 对于给定的字符串,求有多少个 不重叠的子串 出现次数 \(\geq 2\). 思路 枚举子串长度 \(len\),以此作为分界值来对 \(height\) 值进行划分. 显然,对于每一 ...
- Codeforces Round #449 Div. 2 A B C (暂时)
A. Scarborough Fair 题意 对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符. 思路 直接模拟 Code #include < ...
- Linux和Windows兼容
1. 介绍 我们知道Linux上的应用程序是ELF格式的,而Windows则是PE格式 所以要解决这个问题首先二进制加载问题:其次,就是API问题,两者的API完全不同要实现兼容,就需要构建一个虚拟层 ...
- android init.rc命令快速对照表
注1:另外还讲述了怎样输出log: Debugging notes---------------By default, programs executed by init will drop stdo ...
- bitmap自己项目中处理遇到的问题
String path = "图片路径";Bitmap bitmap = BitmapFactory.decodeFile(path);安卓处理图片都是Bitmap,然后取到图片的 ...
- asp.net core 开发环境自定义域名及端口
web项目上右键-> 选择属性-> 选择调试->编辑“应用url” ,再用vs启动web项目即可实现自定义url. 值得注意的是如果报“visual studio无法连接到iis e ...