Check How Long Process Has Been Running in Linux

Check How Long Process Has Been Running in Linux

When monitoring processes in Linux system, can be useful to know how long process has been running. This tutorial shows how to determine that.

First of all, find process ID (PID). Run the following command to get a list of running processes in the system:

ps aux

Use grep command to filter out the output:

ps aux | grep /usr/sbin/sshd

Once process ID was determined, check when process has been started and how long it is been running:

ps -p 657 -o lstart,etime,etimes

Output example:

                 STARTED     ELAPSED ELAPSED
Sat Mar 26 13:43:41 2022 41-12:00:03 3585603

The uptime of all processes can be displayed as follows:

ps -eo pid,args,lstart,etime,etimes

Output example:

    PID COMMAND                                      STARTED     ELAPSED ELAPSED
      1 /sbin/init                  Sat Mar 26 13:43:31 2022 41-12:16:42 3586602
      2 [kthreadd]                  Sat Mar 26 13:43:31 2022 41-12:16:42 3586602
      3 [rcu_gp]                    Sat Mar 26 13:43:31 2022 41-12:16:42 3586602
...
 991124 sshd: root@pts/0            Sat May  7 01:39:05 2022       21:08    1268
 991137 /lib/systemd/systemd --user Sat May  7 01:39:06 2022       21:07    1267

Meaning of format specifiers:

  • pid - process ID.
  • args - command name with options and arguments.
  • lstart - absolute time when process was started.
  • etime - elapsed time since the process was started (format: [[DD-]hh:]mm:ss).
  • etimes - elapsed time since the process was started, in seconds.

Leave a Comment

Cancel reply

Your email address will not be published.