Skip to Content

3 Ways to check process running time in Linux

In this blog post, we will discuss three different ways to check the running time of a process in Linux. This is a useful tool for troubleshooting and determining how long specific processes are taking to run. We will also discuss some of the benefits of each method. Let’s get started!

Check process running time with ps command in Linux

The best way to check process running time in Linux is using ps command. Open the terminal and type ps -p pid -o etime,etimes. It will list the process running time.

The ps command can be used to view information about all running processes. To use this command, simply type “ps aux” into your terminal. You will then see a list of all running processes, as well as their PID (process ID), and the amount of time they have been running.

  • etime Display elapsed time since the process was started, in the form [[DD-]hh:]mm:ss.
  • etimes Display elapsed time since the process was started, in seconds.

 

You need to pass the -o etimes or -o etime to the ps command. The syntax is:

  • ps -p {PID-HERE} -o etime
  • ps -p {PID-HERE} -o etimes

 

let us find and print the PID creation date. In other words find out when the process was started on Linux, enter:

  • $ sudo ps -p {PID} -o start,etimes,etime
  • $ sudo ps -p {PID} -o start,etimes,etime
  • $ sudo ps -p {PID} -o pid,cmd,start,etimes,etime
  • $ sudo ps -C {process-name} -o pid,cmd,start,etimes,etime

 

Check process CPU time using top command in Linux

The second method is to use the “top” command. This command provides a real-time view of all running processes. It also displays a variety of other information about each process, such as CPU usage and memory usage. To use the top command, simply type “top” into your terminal. You will then see a list of all running processes, sorted by CPU usage.

Top command shows you the total CPU time the task has used since it started. But it doesn’t include the elapsed time. So, don’t get confused between top and ps commands.

Check process running time using proc filesystem in Linux

However, the above command doesn’t show you the exact start time of the process and use the following format to check that. The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information.

It’s sometimes referred to as a process information pseudo-file system. It doesn’t contain ‘real’ files but run time system information (e.g. system memory, devices mounted, hardware configuration, etc).

# ls -ld /proc/16337
dr-xr-xr-x. 9 root root 0 Aug 5 17:20 /proc/16337/

Both of these methods have their own benefits. The “ps” command is great for getting a quick overview of all running processes. The “top” command provides real-time information about each process, but it can be a bit overwhelming to look at.

Whichever method you choose, checking the running time of processes can be a valuable tool for troubleshooting and performance analysis. Try out both methods and see which one works best for you!

We hope this blog post has been helpful. If you have any questions or comments, please feel free to reach out to us! We would be happy to help. Thanks for reading!