Simple ways to check Process running time

I’ll show two tips here on how to check a process’ running time, it’s very helpful for system administrators to know these tips as they may need to clean some abnormal processes. It’s a common issue when using FastCGI with apache.

The first one can be used to examine the start time of a specified process:

[mail@iwork ~]$ ps -ef| grep perl
mail  3495  3324  0  2008 ?        00:00:00 /usr/bin/perl /home/mail/msodisk
[mail@iwork ~]$ ls -ld /proc/3495
dr-xr-xr-x  3 mail mail 0 Oct 10 01:03 /proc/3495/

Here, “Oct, 10 01:03” is the process starting time, please note that, this command only works on 2.6 kernels, when
using it on kernel-2.4 system, the timestamp “Oct, 10 01:03” would be replaced by current system time.

The second express can be used on both 2.4 kernel and 2.6 kernels:

expr $(awk -F. '{print $1}' /proc/uptime) - $(expr $(awk '{print $22}' /proc/${PID}/stat) / 100)

Before using this command, you need to set ${PID}. The following section shows an example:

[mail@cluster90 mail]$ ps -auxxf | grep crawler
mail   813  0.0  0.0  2076  816 ?        SN    2007 550:16 bin/crawler
mail   814  0.0  0.0  2144  756 ?        SN    2007  57:55  _ bin/crawler
[mail@cluster90 mail]$ PID=813
[mail@cluster90 mail]$ expr $(awk -F. '{print $1}' /proc/uptime) - $(expr $(awk '{print $22}' /proc/${PID}/stat) / 100)
39764575

As you see, on this server, the admon’s client-side agent “crawler” has been running for more that one year…… and eat only 1.5MB memory in total.

Acturally, we have had crawler running for more that 2.5 years without any termination and exceptions.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

8 Responses to “Simple ways to check Process running time”

  1. payday says:

    http://www.admon.org is very informative. The article is very professionally written. I enjoy reading http://www.admon.org every day.

  2. Cortaflex says:

    I’ve really enjoyed reading your articles. You obviously know what you are talking about! Your site is so easy to navigate too, I’ve bookmarked it in my favourites :-D

  3. For the second example with the long regular expression, Is the result expressed in milliseconds?

    What does “39764575″ mean?

    Cheers!

  4. joseph says:

    Hi, Juan – It’s the number of seconds the process has been running.

  5. pepion8 says:

    Excellent blog! I really love how it is easy on my eyes and also the details are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your rss feed which should do the trick! Have a nice day!

  6. joseph says:

    Thanks and welcome!

  7. Al says:

    I prefer
    ps -C $processname -o lstart=

  8. […] the expression you see in the code snippet above was the nicest solution I could find (hat tip to joseph for […]

Leave a Reply

© 2014 Admon Linux. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by DigitalOcean