Linux how long a process has been running?

https‮w//:‬ww.lautturi.com
Linux how long a process has been running?

To determine how long a process has been running on a Linux system, you can use the ps command with the -o option to display the start time of the process.

To display the start time of a process, open a terminal window and run the following command:

ps -o lstart -p PID

Replace PID with the process ID of the process you want to check. You can use the ps command without the -p option to list the process IDs of all running processes.

The ps command will display the start time of the process in the format MMM DD HH:MM:SS.

For example, the output might look something like this:

STARTED
Feb 06 06:25:01

In this example, the process started on February 6th at 6:25:01.

To determine how long the process has been running, you can subtract the start time from the current time. You can use the date command to display the current time.

For example, to determine how long the process has been running in seconds, you can use the following command:

echo $(( $(date +%s) - $(date -d "$(ps -o lstart -p PID)" +%s) ))

This will display the number of seconds that have elapsed since the process started.

It's worth noting that the ps command displays the start time of the process in the local time zone of the system. If you want to display the start time in a different time zone, you can use the TZ environment variable to set the time zone.

For example, to display the start time in the UTC time zone, you can use the following command:

TZ=UTC ps -o l
Created Time:2017-10-30 10:17:40  Author:lautturi