Linux下查看进程的启动和运行时间

时间:2022-06-21
本文章向大家介绍Linux下查看进程的启动和运行时间,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

有时需要知道某进程运行的时间,比如我想知道我sra文件转换成fq格式的转化速度。以便我做好时间安排。

1 ps - o命令

$ ps -eo pid,tty,user,comm,lstart,etime|grep fastq

参数说明: pid:进程ID tty:终端 user:用户 comm:进程名 lstart:开始时间 etime:运行时间

运行结果如下:

 91413 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91414 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91415 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91416 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91417 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91418 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91419 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91420 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91421 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91422 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91423 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91424 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91425 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91426 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91427 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91428 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91429 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91430 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05
 91431 pts/0    root     fastq-dump      Tue May 21 10:01:44 2019       45:05

2 ps -efps aux命令

ps -ef:标准格式显示进程 ps -aux:BSD格式显示进程

(base) pc@pc-System-Product-Name:/project/raw_fq$ ps -ef |head
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 5月09 ?       00:00:08 /sbin/init splash
root          2      0  0 5月09 ?       00:00:00 [kthreadd]
root          3      2  0 5月09 ?       00:00:00 [rcu_gp]
root          4      2  0 5月09 ?       00:00:00 [rcu_par_gp]
root          6      2  0 5月09 ?       00:00:00 [kworker/0:0H-kb]
root          8      2  0 5月09 ?       00:00:00 [mm_percpu_wq]
root          9      2  0 5月09 ?       00:00:03 [ksoftirqd/0]
root         10      2  0 5月09 ?       00:01:04 [rcu_sched]
root         11      2  0 5月09 ?       00:00:00 [rcu_bh]
(base) pc@pc-System-Product-Name:/project/raw_fq$ ps aux|head
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0 225888  6456 ?        Ss   5月09   0:08 /sbin/init splash
root          2  0.0  0.0      0     0 ?        S    5月09   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        I<   5月09   0:00 [rcu_gp]
root          4  0.0  0.0      0     0 ?        I<   5月09   0:00 [rcu_par_gp]
root          6  0.0  0.0      0     0 ?        I<   5月09   0:00 [kworker/0:0H-kb]
root          8  0.0  0.0      0     0 ?        I<   5月09   0:00 [mm_percpu_wq]
root          9  0.0  0.0      0     0 ?        S    5月09   0:03 [ksoftirqd/0]
root         10  0.0  0.0      0     0 ?        I    5月09   1:04 [rcu_sched]
root         11  0.0  0.0      0     0 ?        I    5月09   0:00 [rcu_bh]

USER:用户名 %CPU:进程占用的CPU百分比 %MEM:占用内存的百分比 VSZ:该进程使用的虚拟內存量(KB) RSS:该进程占用的固定內存量(KB)(驻留中页的数量) STAT:进程的状态 START:该进程被触发启动时间 TIME:该进程实际使用CPU运行的时间

top命令

top也可以看进程信息,与ps区别如下

  • ps看命令执行那刻的进程信息,top是持续监视,ctrl c退出
  • ps只是查看进程,而top还可以监视系统性能,如平均负载,cpu和内存的消耗

总体来说, ps主要是查看进程的,尤其你关心的进程 top主要看cpu,内存使用情况,及占用资源最多的进程由高到低排序,关注点在于资源占用情况