Come scoprire da quanto tempo un processo è in esecuzione, in Linux
In questo breve articolo ti aiutiamo a scoprire da quanto tempo un processo attivo è in esecuzione sul tuo server Linux.
A tale scopo utilizziamo il comando "ps", che viene utilizzato per visualizzare le informazioni sui processi attivi.
Ci siamo già occupati in un altro articolo del comando "ps": oggi ci focalizziamo sul tempo di esecuzione di un processo.
Innanzitutto identifichiamo il PID, cioè l'identificativo, di uno specifico processo, utilizzando il comando "pidof".
Ad esempio vogliamo sapere da quanto tempo il server web Apache è in esecuzione:
# pidof httpd
6040 6038 6035 6034 6033
Il risultato evidenzia che Apache ha vari processi attivi. Prendiamo ad esempio il primo 6040.
Bene, adesso grazie al comando "ps", associato ad alcune "parole chiave", otteniamo informazioni utili relative al tempo di esecuzione di quel processo.
Queste sono le parole chiave che andremo ad utilizzare
- etime: indica il tempo trascorso dall'avvio del processo, nel formato minuti:secondi, e, se necessario, giorni e ore: [[DD-] hh:] mm: ss
- etimes indica il tempo trascorso dall'avvio del processo, in secondi
Per conoscere il tempo di esecuzione del nostro processo, in giorni/ore/minuti/secondi, utilizziamo:
# ps -p 6040 -o etime
ELAPSED
04:05:37
La risposta "ELAPSED" è il tempo trascorso dall'avvio del processo.
Analogamente, per saper lo stesso tempo espresso in secondi, utilizziamo:
# ps -p 6040 -o etimes
ELAPSED
14749
Bene, adesso invece di soffermarci su un singolo processo, visualizziamo il tempo di attività, nel formato "etime", di tutti i processi:
# ps -eo pid,comm,lstart,etime,time,args
Il risultato sarà la lista di tutti i processi:
PID COMMAND STARTED ELAPSED TIME COMMAND
1 systemd Thu Feb 6 06:08:17 2020 23-02:22:51 00:01:48 /usr/lib/systemd/systemd --switched-root --system --deserializ
2 kthreadd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kthreadd]
4 kworker/0:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/0:0H]
6 ksoftirqd/0 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:10 [ksoftirqd/0]
7 migration/0 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/0]
8 rcu_bh Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [rcu_bh]
9 rcu_sched Thu Feb 6 06:08:17 2020 23-02:22:51 00:14:15 [rcu_sched]
10 lru-add-drain Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [lru-add-drain]
11 watchdog/0 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:05 [watchdog/0]
12 watchdog/1 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:05 [watchdog/1]
13 migration/1 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/1]
14 ksoftirqd/1 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:16 [ksoftirqd/1]
16 kworker/1:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/1:0H]
17 watchdog/2 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:05 [watchdog/2]
18 migration/2 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/2]
19 ksoftirqd/2 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:13 [ksoftirqd/2]
21 kworker/2:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/2:0H]
22 watchdog/3 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:05 [watchdog/3]
23 migration/3 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/3]
24 ksoftirqd/3 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:11 [ksoftirqd/3]
26 kworker/3:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/3:0H]
27 watchdog/4 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:04 [watchdog/4]
28 migration/4 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/4]
29 ksoftirqd/4 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:09 [ksoftirqd/4]
31 kworker/4:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/4:0H]
32 watchdog/5 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:04 [watchdog/5]
33 migration/5 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/5]
34 ksoftirqd/5 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:05 [ksoftirqd/5]
36 kworker/5:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/5:0H]
37 watchdog/6 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:04 [watchdog/6]
38 migration/6 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [migration/6]
39 ksoftirqd/6 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:09 [ksoftirqd/6]
41 kworker/6:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/6:0H]
42 watchdog/7 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:04 [watchdog/7]
43 migration/7 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:01 [migration/7]
44 ksoftirqd/7 Thu Feb 6 06:08:17 2020 23-02:22:51 00:01:17 [ksoftirqd/7]
46 kworker/7:0H Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kworker/7:0H]
48 kdevtmpfs Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kdevtmpfs]
49 netns Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [netns]
50 khungtaskd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [khungtaskd]
51 writeback Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [writeback]
52 kintegrityd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kintegrityd]
53 bioset Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [bioset]
54 bioset Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [bioset]
55 bioset Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [bioset]
56 kblockd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kblockd]
57 md Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [md]
58 edac-poller Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [edac-poller]
59 watchdogd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [watchdogd]
68 kswapd0 Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kswapd0]
69 ksmd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [ksmd]
70 khugepaged Thu Feb 6 06:08:17 2020 23-02:22:51 00:04:06 [khugepaged]
71 crypto Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [crypto]
79 kthrotld Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kthrotld]
81 kmpath_rdacd Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kmpath_rdacd]
82 kaluad Thu Feb 6 06:08:17 2020 23-02:22:51 00:00:00 [kaluad]
84 kpsmoused Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [kpsmoused]
86 ipv6_addrconf Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [ipv6_addrconf]
99 deferwq Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [deferwq]
137 kauditd Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:10 [kauditd]
346 scsi_eh_0 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_0]
348 scsi_tmf_0 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_0]
355 ata_sff Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [ata_sff]
616 scsi_eh_1 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_1]
619 scsi_tmf_1 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_1]
624 scsi_eh_2 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_2]
630 scsi_tmf_2 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_2]
633 scsi_eh_3 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_3]
635 scsi_tmf_3 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_3]
638 scsi_eh_4 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_4]
643 scsi_tmf_4 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_4]
646 scsi_eh_5 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_5]
647 scsi_tmf_5 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_5]
648 scsi_eh_6 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_eh_6]
656 scsi_tmf_6 Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [scsi_tmf_6]
859 ttm_swap Thu Feb 6 06:08:18 2020 23-02:22:50 00:00:00 [ttm_swap]
881 poll_megasas0_s Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [poll_megasas0_s]
946 kdmflush Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [kdmflush]
947 bioset Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [bioset]
957 kdmflush Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [kdmflush]
958 bioset Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [bioset]
974 jbd2/dm-0-8 Thu Feb 6 06:08:19 2020 23-02:22:49 00:05:28 [jbd2/dm-0-8]
975 ext4-rsv-conver Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 [ext4-rsv-conver]
1062 systemd-journal Thu Feb 6 06:08:19 2020 23-02:22:49 00:01:10 /usr/lib/systemd/systemd-journald
1087 lvmetad Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 /usr/sbin/lvmetad -f
1093 systemd-udevd Thu Feb 6 06:08:19 2020 23-02:22:49 00:00:00 /usr/lib/systemd/systemd-udevd
1159 kworker/u16:1 Sat Feb 29 06:07:25 2020 02:23:43 00:00:00 [kworker/u16:1]
1428 kvm-irqfd-clean Thu Feb 6 06:08:20 2020 23-02:22:48 00:00:00 [kvm-irqfd-clean]
1748 jbd2/sda1-8 Thu Feb 6 06:08:20 2020 23-02:22:48 00:00:00 [jbd2/sda1-8]
1755 ext4-rsv-conver Thu Feb 6 06:08:20 2020 23-02:22:48 00:00:00 [ext4-rsv-conver]
1917 kworker/2:1H Thu Feb 6 06:08:24 2020 23-02:22:44 00:00:00 [kworker/2:1H]
1918 kworker/4:1H Thu Feb 6 06:08:31 2020 23-02:22:37 00:00:00 [kworker/4:1H]
1919 kworker/5:1H Thu Feb 6 06:08:55 2020 23-02:22:13 00:00:00 [kworker/5:1H]
1943 auditd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:19 /sbin/auditd
1967 rngd Thu Feb 6 06:09:18 2020 23-02:21:50 00:03:10 /sbin/rngd -f
1974 smartd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:00 /usr/sbin/smartd -n -q never
1977 lsmd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:04 /usr/bin/lsmd -d
1978 irqbalance Thu Feb 6 06:09:18 2020 23-02:21:50 00:03:10 /usr/sbin/irqbalance --foreground
1995 abrtd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:00 /usr/sbin/abrtd -d -s
1997 dsm_sa_eventmgr Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:17 /opt/dell/srvadmin/sbin/dsm_sa_eventmgrd
1998 abrt-watch-log Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO
2002 polkitd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:08 /usr/lib/polkit-1/polkitd --no-debug
2006 dbus-daemon Thu Feb 6 06:09:18 2020 23-02:21:50 00:01:37 /usr/bin/dbus-daemon --system --address=systemd: --nofork --no
2023 dsm_om_connsvcd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:00 /opt/dell/srvadmin/sbin/dsm_om_connsvcd -run
2028 dsm_om_connsvcd Thu Feb 6 06:09:18 2020 23-02:21:50 00:37:37 /opt/dell/srvadmin/sbin/dsm_om_connsvcd -run
2032 chronyd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:02 /usr/sbin/chronyd
2048 NetworkManager Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:26 /usr/sbin/NetworkManager --no-daemon
2049 systemd-logind Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:38 /usr/lib/systemd/systemd-logind
2056 crond Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:03 /usr/sbin/crond -n
2057 atd Thu Feb 6 06:09:18 2020 23-02:21:50 00:00:00 /usr/sbin/atd -f
2089 kworker/5:1 Sun Feb 23 11:30:00 2020 5-21:01:08 00:00:03 [kworker/5:1]
2199 dsm_sa_datamgrd Thu Feb 6 06:09:19 2020 23-02:21:49 00:13:35 /opt/dell/srvadmin/sbin/dsm_sa_datamgrd
2439 httpd Thu Feb 6 06:09:25 2020 23-02:21:43 00:09:45 /usr/sbin/httpd -DFOREGROUND
2443 sshd Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:13 /usr/sbin/sshd -D
2445 vsftpd Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:01 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
2448 tuned Thu Feb 6 06:09:25 2020 23-02:21:43 00:02:32 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
2452 rsyslogd Thu Feb 6 06:09:25 2020 23-02:21:43 00:01:34 /usr/sbin/rsyslogd -n
2458 opendkim Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:13 /usr/sbin/opendkim -x /etc/opendkim.conf -P /var/run/opendkim/
2460 fail2ban-server Thu Feb 6 06:09:25 2020 23-02:21:43 00:33:30 /usr/bin/python2 /usr/bin/fail2ban-server -xf start
2463 xinetd Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
2567 VVAgent Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:14 /opt/BUAgent/VVAgent -d -p /opt/BUAgent
2610 mysqld Thu Feb 6 06:09:25 2020 23-02:21:43 12:06:47 /usr/sbin/mysqld
2658 agetty Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:00 /sbin/agetty --noclear tty1 linux
2915 master Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:08 /usr/libexec/postfix/master -w
2920 qmgr Thu Feb 6 06:09:25 2020 23-02:21:43 00:00:01 qmgr -l -t unix -u
3132 buagent Thu Feb 6 06:09:26 2020 23-02:21:42 00:11:38 /opt/BUAgent/buagent --path "/opt/BUAgent"
3153 kworker/7:1H Thu Feb 6 06:09:30 2020 23-02:21:38 00:00:00 [kworker/7:1H]
3159 kworker/1:1H Thu Feb 6 06:09:45 2020 23-02:21:23 00:00:00 [kworker/1:1H]
3689 kworker/u16:2 Sat Feb 29 07:15:01 2020 01:16:07 00:00:00 [kworker/u16:2]
3823 kworker/3:1H Thu Feb 6 06:09:51 2020 23-02:21:17 00:00:00 [kworker/3:1H]
3864 dsm_sa_snmpd Thu Feb 6 06:09:56 2020 23-02:21:12 00:11:47 /opt/dell/srvadmin/sbin/dsm_sa_snmpd
3880 kworker/6:1H Thu Feb 6 06:10:06 2020 23-02:21:02 00:00:00 [kworker/6:1H]
3882 dsm_sa_datamgrd Thu Feb 6 06:10:07 2020 23-02:21:01 00:00:00 /opt/dell/srvadmin/sbin/dsm_sa_datamgrd
3896 kworker/0:1H Thu Feb 6 06:11:11 2020 23-02:19:57 00:00:00 [kworker/0:1H]
4088 pickup Sat Feb 29 07:28:12 2020 01:02:56 00:00:00 pickup -l -t unix -u
5187 kworker/0:0 Sat Feb 29 08:00:00 2020 31:08 00:00:00 [kworker/0:0]
5846 kworker/7:2 Thu Feb 13 15:06:16 2020 15-17:24:52 00:00:11 [kworker/7:2]
5949 httpd Sat Feb 29 08:20:22 2020 10:46 00:00:02 /usr/sbin/httpd -DFOREGROUND
5954 httpd Sat Feb 29 08:20:23 2020 10:45 00:00:02 /usr/sbin/httpd -DFOREGROUND
5973 sshd Sat Feb 29 08:21:04 2020 10:04 00:00:00 sshd: root@pts/0
5985 bash Sat Feb 29 08:21:12 2020 09:56 00:00:00 -bash
6033 httpd Sat Feb 29 08:21:18 2020 09:50 00:00:02 /usr/sbin/httpd -DFOREGROUND
6035 httpd Sat Feb 29 08:21:19 2020 09:49 00:00:03 /usr/sbin/httpd -DFOREGROUND
6059 httpd Sat Feb 29 08:21:52 2020 09:16 00:00:02 /usr/sbin/httpd -DFOREGROUND
6126 httpd Sat Feb 29 08:25:03 2020 06:05 00:00:01 /usr/sbin/httpd -DFOREGROUND
6176 httpd Sat Feb 29 08:26:10 2020 04:58 00:00:03 /usr/sbin/httpd -DFOREGROUND
6181 httpd Sat Feb 29 08:26:11 2020 04:57 00:00:00 /usr/sbin/httpd -DFOREGROUND
6332 httpd Sat Feb 29 08:30:54 2020 00:14 00:00:00 /usr/sbin/httpd -DFOREGROUND
6333 httpd Sat Feb 29 08:30:55 2020 00:13 00:00:00 /usr/sbin/httpd -DFOREGROUND
6334 httpd Sat Feb 29 08:30:55 2020 00:13 00:00:00 /usr/sbin/httpd -DFOREGROUND
6342 httpd Sat Feb 29 08:30:57 2020 00:11 00:00:00 /usr/sbin/httpd -DFOREGROUND
6343 httpd Sat Feb 29 08:30:57 2020 00:11 00:00:00 /usr/sbin/httpd -DFOREGROUND
6344 httpd Sat Feb 29 08:30:57 2020 00:11 00:00:00 /usr/sbin/httpd -DFOREGROUND
6345 httpd Sat Feb 29 08:30:57 2020 00:11 00:00:00 /usr/sbin/httpd -DFOREGROUND
6353 ps Sat Feb 29 08:31:08 2020 00:00 00:00:00 ps -eo pid,comm,lstart,etime,time,args
8097 tlsmgr Thu Feb 6 08:09:25 2020 23-00:21:43 00:00:01 tlsmgr -l -t unix -u
10794 kworker/5:0 Fri Feb 28 20:23:46 2020 12:07:22 00:00:00 [kworker/5:0]
11849 kworker/4:2 Fri Feb 28 20:40:00 2020 11:51:08 00:00:00 [kworker/4:2]
13237 kworker/6:1 Thu Feb 27 20:10:07 2020 1-12:21:01 00:00:01 [kworker/6:1]
16855 kworker/1:1 Fri Feb 28 22:30:00 2020 10:01:08 00:00:00 [kworker/1:1]
18177 kworker/4:1 Sat Feb 8 14:59:57 2020 20-17:31:11 00:00:14 [kworker/4:1]
18568 kworker/2:1 Fri Feb 28 23:10:00 2020 09:21:08 00:00:00 [kworker/2:1]
20507 uptimed Wed Feb 26 15:07:43 2020 2-17:23:25 00:00:01 /usr/sbin/uptimed -f
22379 kworker/7:0 Sat Feb 29 00:30:00 2020 08:01:08 00:00:00 [kworker/7:0]
25292 kworker/6:2 Sat Feb 29 02:00:00 2020 06:31:08 00:00:00 [kworker/6:2]
25437 kworker/3:1 Fri Feb 28 15:03:58 2020 17:27:10 00:00:03 [kworker/3:1]
25671 kworker/0:2 Wed Feb 19 13:00:01 2020 9-19:31:07 00:00:15 [kworker/0:2]
25717 kworker/1:0 Sat Feb 22 18:50:00 2020 6-13:41:08 00:00:10 [kworker/1:0]
28698 kworker/3:0 Fri Feb 28 16:15:58 2020 16:15:10 00:00:00 [kworker/3:0]
31733 kworker/2:2 Mon Feb 24 20:30:00 2020 4-12:01:08 00:00:06 [kworker/2:2]
Vediamo il significato di ogni colonna
PID: è l'id del processo
COMMAND: è il comando che ha lanciato il processo, senza opzioni o argomenti
STARTED: è la data di avvio del processo.
ELAPSED: è il tempo di esecuizone del processo, nel nostro caso nel formato "etime"
TIME: tempo cumulativo di utilizzo della cpu, espresso nel formato "etime".
COMMAND: è il comando che ha lanciato il processo, comprensivo di opzioni e argomenti
Per maggiori dettagli relativi al comando ps, si rimanda alla sua manual page:
# man ps