察看运行的进程开启的时间?

本文深入探讨了Linux系统中ps命令的-o与-O选项的用法,指导如何通过这些选项获取进程的启动时间、用户、命令等详细信息。文章详细解释了各选项的功能及输出格式,并提供了实际示例帮助读者轻松上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用ps -ef察看运行的进程,但是如何知道这些进程启动的时间呢?我们使用ps的参数-o。-o表示user defined format。 格式是

       -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 columns named "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.


例如:

[dwap@abcdefg:/home/dwapp/admin/alisql/task/rtdc]ps -eo pid,tty,user,comm,stime,etime | grep python
14433 ?        dwap    python          00:00    07:26:45
14436 ?        dwap    python          00:00    12:26:45
15905 ?        dwap    python          07:45    01:41:23


2. -O format,和-o非常相似,但是不同的是-O有一些默认的格式。和

-o pid,format,state,tname,time,command一样。

       -O format       is like -o, but preloaded with some default columns. Identical to -o pid,format,state,tname,time,command or -o pid,format,tname,time,cmd, see -o below.


       O format        is preloaded o (overloaded).
                       The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be used to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the
                       desired behavior is obtained (sorting or formatting), specify the option in some other way (e.g. with -O or --sort). When used as a formatting option, it is identical to -O, with the BSD personality.

例如:

[root@asdfadf~]# ps -eO pid
  PID   PID S TTY          TIME COMMAND
    1     1 S ?        00:00:00 /sbin/init
    2     2 S ?        00:00:00 [kthreadd]
    3     3 S ?        00:00:00 [migration/0]
    4     4 S ?        00:00:00 [ksoftirqd/0]
    5     5 S ?        00:00:00 [migration/0]
    6     6 S ?        00:00:03 [watchdog/0]
    7     7 S ?        00:00:00 [migration/1]


定义的PID之后,有一串默认的列。


转载于:https://my.oschina.net/jccpp/blog/127967

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值