Linux: Find out how long a process has been running

If you need to figure out how long a process has been running (e.g. to identify long running processes or just monitor some processes), you can use the -o etime option of the ps command. Here the description from the ps manual:

etime elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.

If you want to monitor a given process (or in my case multiple processes started with the same command), you can combine it with -o command which will output the command line used to start the process and grep it:

The information about elapsed time comes from /proc/<pid>/stat but it is here displayed in a human readable form. Anyway from /proc/<pid>/stat you’d get a number of jiffies and need to find out how to convert it to something more understandable… So let’s stick to ps…

If you know the pid of the process it’s even easier, you can just use the -p option of ps instead of grep:

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.OkRead more