有没有办法检查进程 X 运行了多长时间或何时启动?我首先想到的是ps
命令,但什么也没找到。
答案1
最简单的方法是ps -ef
查看 STIME 列以了解其启动时间。对于进程 X,使用ps -ef | grep -i X
。更复杂的方法(对于已用时间是必需的)是使用选项-o
。使用:
相当于ps -ef
ps -eo uid,pid,ppid,c,stime,tty,time,cmd
从手册页中:
etime ELAPSED elapsed time since the process was started, in the form [[DD-]hh:]mm:ss. start STARTED time the command started. If the process was started less than 24 hours ago, the output format is "HH:MM:SS", else it is " <mm dd" (where Mmm is a three-letter month name). See also lstart, bsdstart, start_time, and stime.
因此,对于名为“X”的进程,一个简单的示例是:
搜索运行的命令:ps -eo pid,cmd,start,etime | grep -i X
搜索可执行文件名称:ps -eo pid,comm,start,etime | grep -i X
搜索两者:ps -eo pid,comm,cmd,start,etime | grep -i X
如果您要经常使用它,您可能需要设置一个别名。