In a Linux environment, you often need to know exactly how long a specific service or application has been running. While you can easily check the total system uptime with the uptime command, diagnosing memory leaks, tracking daemon restarts, or monitoring long-running scripts requires isolating the lifespan of an individual process.
Ubuntu provides several ways to interrogate running processes. The most efficient method for determining the exact age and start time of a specific process is by combining the ps (process status) command with output formatting flags.
This guide explains how to find the exact uptime and start time of any process running on your Ubuntu system.
Finding the Process ID (PID)
Before you can check the uptime of a process, you must know its unique Process ID (PID).
- Open your Ubuntu terminal.
- Use the
pgrepcommand followed by the name of your application. For example, to find the PID of the Nginx web server, type:pgrep nginx - The terminal will return a number (or a list of numbers if there are multiple worker processes). Note this number down (e.g.,
1234).
Checking the Exact Uptime Using ps
Once you have the PID, you can ask the ps command to output only the elapsed time since that specific process was launched.
- Use the following command syntax, replacing
1234with your actual PID:ps -p 1234 -o etime= - Press Enter.
The terminal will output the elapsed time in a standard format (Days-Hours:Minutes:Seconds). For example, an output of 03-14:22:15 means the process has been running continuously for 3 days, 14 hours, 22 minutes, and 15 seconds.
Checking the Exact Start Time
If you prefer to know the exact calendar date and clock time the process began, rather than just the elapsed duration, you can change the formatting flag.
- Use the
lstartflag instead ofetime:ps -p 1234 -o lstart= - Press Enter.
The terminal will output the precise timestamp of when the process was initiated, such as: Tue Oct 10 14:30:00 2023.
The One-Line Shortcut
If you do not want to find the PID first, you can combine ps and grep to search by the process name and display the uptime in a single, robust command.
ps -eo pid,comm,etime | grep "nginx"
This command lists every running process (-e), formats the output (-o) to show only the PID, the command name, and the elapsed time, and then pipes that list into grep to filter for “nginx”. The output will give you a clean list of all matching processes and exactly how long they have been active.