howto get the uptime of a process

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
JustinHoMi
Posts: 17
Joined: Mon Oct 07, 2002 3:42 pm

howto get the uptime of a process

Post by JustinHoMi »

Howdy. Does anybody know how to get the uptime of a particular process? I'd imagine it's somewhere in /proc/<pid> but a lot of the files aren't too descriptive.

Justin
Alain Tesio
Posts: 7
Joined: Sat Oct 19, 2002 5:16 pm
Location: Paris, France
Contact:

Post by Alain Tesio »

ps --no-headers -o etime -p `pidof foo`

but you'll have to parse the output or find the right option to get seconds

The format of /proc/pid/stat is defined in the kernel sources in fs/proc/array.c
JustinHoMi
Posts: 17
Joined: Mon Oct 07, 2002 3:42 pm

Post by JustinHoMi »

Oh great thanks! I've played with this for the last day, and the ps output isn't really good for monitoring. It doesn't put placeholders for empty values.... for instance if a process has been running for 2 days, 3 hours, 6 minutes, and 12 seconds, it outputs something like:

02-03:06:12

but if the process has only been running for 10 minutes it only reports

10:00

That makes writing a script to parse the data a pain. I'm not sure if /proc/pid/stat actually holds the time. If it does I sure can't figure it out. Nothing in there resembles a unix timestamp (for a possible process-start time) and nothing increments every second. I'll keep playing with it tho....

Thanks again,
Justin
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests