Taking date difference

Hi,

There is requirement in our project where in we have to calculate the elpased time of the process which are running and then if the elapsed time is greater than specific time we have to send a mail.

In order to calculate the elapsed time we ahve use "ps -ef" command.The time displayed in ps -ef command is "06:57"
How to take the difference of the above obtain time with current system time?:confused:
And then how to compare the obtained with specific time let's say 45 minutes?

Thanks in Advance!!

The time you see with ps -ef isn't the time you started the process, but the CPU time the process has used so far. Example: a daemon like cron will use almost no CPU time, since it only wakes up once a minute, starts some processes (if any), and then goes to sleep again. A process that uses a lot of CPU (calculations, encryption, ...) will quickly accumulate a lot of CPU time.

In many versions of "ps" the "STIME" column is the process start time hh:mm:ss. Beware that the column format changes to the start date (rather than start time) once the process has been running for more than 24 hours.

If the job is backgrounded it may be easier to modify the original job script to set an "at -t +45 minutes" job to check whether the process is still present.

To properly answer the question we need to know your Operating System, Preferred Shell, and how the process is started.

Question:
Why didnt you use timex ( or time ...) command?

Thanks all for the reply :slight_smile:

Since "ps -ef" command gives us the exact start time,we are using this command.
For example

$ ps -ef | grep "DSD.RUN"
dsadm    29826 13475  1 23:53 ?        00:00:00 phantom DSD.RUN HEW_JOBS 0/0/1/0/0
dsadm     3200 28456  0 00:17 pts/3    00:00:00 grep DSD.RUN

$ date
Wed May  6 00:21:26 EDT 2009

In the above example we are using "23:53" as start time and then comapring it system time "00:21" and if the result greater than 45 minutes ,then send the mail to user.Our main problem is that since this process will run in night :eek: so it is very difficult to calculate the elapsed time :confused:

The system details are:
Operating System:GNU/Linux
Preferred Shell:korn

I definitaly would have opted for a script which :
launches your program followed by an at now + 45 min <check_presence_script
to do this task