How To Check The Running Time Of A Process In Linux/Unix ?


In Unix like operating systems, a process is a program in execution. The running time of a process means how long a process has been running on a system. There are different ways to determine the running time of processes in the Linux or Unix system for example by using an etime option with ps command. So let us find the running time of a process.

Process Identifier(PID)

There can be multiple processes running in a system. Kernel identifies each process with a unique id called process id or PID. To find the PID of a process first open your terminal and then execute the following command –

pidof process_name

For example to find the PID of Rhythmbox use –

pidof Rhythmbox

Now you can see the PID of Rhythmbox which is 2423. We need to find the PID of a process in order to find the running time using the ps command as given in the coming section.

Display the running time using ps command

The ps (process status) command displays information about a selection of active/running processes. We will use the following two options to display running time –

etime – It displays elapsed time since the process was started, in [[DD-]hh:]mm:ss format.

etimes– It displays elapsed time since the process was started in seconds

Find running time using etime option

To display the running time use the following command in your terminal –

ps -p PID -o etime

For example to display the running time of the process with PID 2423, use –

ps -p 2423 -o etime

Find running time using etimes option

To display the running time use the following command in your terminal, this will display the running time in seconds –

ps -p PID -o etimes

For example to display the running time of process with PID 2423, use –

ps -p 2423 -o etimes

Conclusion

In this article, you learned to find the PID and then use it to determine how long a process has been running in a system. If you want to know more about ps command then see its manual page by using man ps.

Now if you want to know more about the usage of ps command you can read how to check the status of active processes using ps command.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.