See how long a given process has been running

Nov 28, '12 07:30:00AM

Contributed by: robg

I wanted to find out how long a certain background process had been running. There's a column for CPU Time in Activity Monitor, but that's not real clock time.

It turns out you can get this information with ps, via the etime keyword. So to get a list of every running process, in decreasing order of run time, just use this command:

ps -ax -o etime,command -c
To see the results for a single process, just add a grep at the end for the process' name. For example:
$ ps -ax -o etime,command -c | grep AppleVNCServer
03-08:09:16 AppleVNCServer
So on my Mac, the AppleVNCServer has been running for three days, eight hours, nine minutes, and 16 seconds. I have a need to do this pretty regularly, so I turned it into a simple command line app:
#!/bin/bash

# Display the time a given process has been running
# Use the process name when calling the command

ps -ax -o etime,command -c | grep $1
I saved that to a file named psup, and made it executable with chmod 755 psup. Now I can just type psup SomeProcess to see the uptime for SomeProcess.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20121127064752309