我使用以下内容:
ptime=`ps aux | grep $PROCESS | awk {'print $9'} | head -$i | tail -1
但我以HH::MM
格式获得了该过程的开始时间。
但是我希望使用shell脚本<{1}}格式的时间
答案 0 :(得分:1)
您可以将ps
与手册页
来自Linux机器上ps
的手册页的信息。
-A Select all processes. Identical to -e.
-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.
etime ELAPSED elapsed time since the process was started, in the
form [[dd-]hh:]mm:ss.
ps -Ao pid,etime,comm | grep <process>
$ ps -Ao pid,etime,comm | grep sftp-server
85587 16-02:17:01 sftp-server