linux ps查看完整时间,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

查看程序是否启动或者关闭--比如查看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”选项可以开启线程查看.下面的命令列出了由进程号为的进程创建的所有线程. 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占用率 % ...

随机推荐

PostGIS(解压版)安装

1.软件下载 postgresql-9.6.1-1-windows-x64-binaries.zip https://www.postgresql.org/download/windows/ post ...

详解javascript 存储

javascript用于存储的方式可谓是多种多样,善于应用‘存储’可以大大的提高网站的性能,博主结合日常开发常见需求做一下总结,希望对大家有用- 1.cookie 存储大小:   4kb左右,以20个 ...

eclipse中svn插件的安装和tortoiseSVN的安装

在项目的开发中一般都需要用到版本控制,其中用的比较多的就是svn(subVersion),svn的使用既可以以插件的形式,也可以以客户端的形式使用.今天就介绍一下eclipse中svn插件的2种安装方 ...

MyBatis-xml配置SQL文件中,传入List数组、基本类型String、int……、与自定义类型的方法

//基本类型 @Override public String queryItemNumber(String packId) throws Exception { // TODO Auto-genera ...

win8下 msvcr100d.dll文件缺失解决方法

一.如果在运行某软件或编译程序时提示缺少.找不到msvcp100d.dll等类似提示,您可将从载来的msvcp100d.dll拷贝到指定目录即可(一般是system系统目录或放到软件同级目录里面),或 ...

MongoDB实战性能优化

1. 性能优化分类 mongodb性能优化分为软件层面和操作系统层面. 软件层面,一般通过修改mongodb软件配置参数来达到,这个需要非常熟悉mongodb里面的各种配置参数: 而操作系统层面,相对 ...

CS229 6.4 Neurons Networks Autoencoders and Sparsity

BP算法是适合监督学习的,因为要计算损失函数,计算时y值又是必不可少的,现在假设有一系列的无标签train data:  ,其中 ,autoencoders是一种无监督学习算法,它使用了本身作为标签以 ...

[转帖]win10 .Net Runtime Optimization Service占用大量CPU资源解决方法

win10 .Net Runtime Optimization Service占用大量CPU资源解决方法 https://blog.csdn.net/cwg2552298/article/detail ...

hive表增量抽取到oracle数据库的通用程序(二)

hive表增量抽取到oracle数据库的通用程序(一) 前一篇介绍了java程序的如何编写.使用以及引用到的依赖包.这篇接着上一篇来介绍如何在oozie中使用该java程序. 在我的业务中,分为两段: ...

sencha touch list(列表) item(单行)单击事件触发顺序

测试代码如下 Ext.define('app.view.new.List', { alternateClassName: 'newList', extend: 'app.view.util.MyLis ...

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值