In this blog post, we will discuss three different ways to check the start 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!
Table of Contents
Check process start time with ps command in Linux
We can easily check the process start time in Linux using the ps command. Open the terminal and type ps -p pid -o lstart,start,etime,etimes. It will list the process start time in the command output.
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.
- lstart Display time the command started.
- 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.
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!Let us use the systemd process as an example.
The program systemd is the process with process ID 1. It is responsible for initializing the system in the required way. systemd is started directly by the kernel and resists signal 9, which normally terminates processes. All other programs are either started directly by systemd or by one of its child processes.
The “ps” command is a tool that displays information about active processes on the system. By default, it will display information about all active processes on the system. However, you can use the “-o” option to display information based on a user-defined format.
We can use the following command to get the start time of process systemd. It should be same with the system start time.
$ ps -p 1 -o lstart,start,etimes,etime
STARTED STARTED ELAPSED ELAPSED
Wed Jun 2 06:40:14 2021 Jun 02 42622002 493-07:26:42
Let’s check the system start time with who command.
$ uptime -s
2021-06-02 06:40:14
$ uptime
14:29:09 up 493 days, 7:48, 1 user, load average: 0.00, 0.01, 0.05
You need to pass the -o lstart, -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 lstart,etimes,etime
- $ sudo ps -p {PID} -o pid,cmd,start,etimes,etime
- $ sudo ps -C {process-name} -o pid,cmd,start,etimes,etime
Related: Check Network Usage by Process with Linux Nethogs command
Check process start time using proc filesystem in Linux
However, the above command doesn’t show you the exact start time of the process. 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/1
dr-xr-xr-x 9 root root 0 Jun 2 2021 /proc/1
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.
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.
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!