Understanding ps elapsed time format for long running processes

I’m using a ps command as part of an exercise to identify processes running longer than a given threshold.

I’m using the following template to get the elapsed time for a know process command:

ps -eo etime,command | grep <something to identify a process> | grep -v grep | awk '{print $1}'

I notice with short-running processes, the etime (elapsed time) value takes the format minutes:seconds and from this I can easily determine how long a process has been running.

For very long running processes (days long), I don’t understand the format.

I have a MySQL server process that htop shows as running for 126 hours.

Executing ps -eo etime,command | grep mysql | grep -v grep | awk '{print $1}' gives me a value of 9-03:35:32.

My best guess is that this means 9 something, 3 hours, 35 minutes, 32 seconds. I can’t figure out what the units are for the 9.

The process in question has been running 126 hours, about 5.25 days. This suggests that the 9 in the above output does not represent days. They can’t be half days either as (9 * 12) hours + 3 hours + 35 minutes + 32 seconds is less than 5 days.

How do I interpret the elapsed time value I am seeing for long-running processes? What units accompany the 9 in the above output?

Asked By: Jon Cram


According to the standard:

In the POSIX locale, the elapsed time since the process was started, in the form:


where dd shall represent the number of days, hh the number of hours, mm the number of minutes, and ss the number of seconds. The dd field shall be a decimal integer. The hh, mm, and ss fields shall be two-digit decimal integers padded on the left with zeros.

So, the 9 means days, whether you believe it or not. Could you be misinterpreting the output from htop? What does top (which has a time format of minutes:seconds) say? Are you certain that the field you are looking at in htop is equivalent to etime? (for example, could it means 126 minutes of CPU time?)

Answered By: Random832
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.