使用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之后,有一串默认的列。