Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have initiated 50 processes and in one file "say start_time", I have stored when process was started and in another file "say end_time", I have stored when process finished. files are like below -

Start time - 
Start time for Process A : 15/09/26 21:02:13
Start time for Process B : 15/09/26 20:06:14
Start time for Process C : 15/09/26 13:20:52
Start time for Process D : 15/09/26 11:23:46

End time file 
End time for Process B : 15/09/26 21:13:38
End time for Process D : 15/09/26 12:31:29
End time for Process A : 15/09/26 22:06:11
End time for Process C : 15/09/26 12:17:10

Now I want to calculate execution time for each process like Process A : 10 mins Process B : 5 mins etc.

share|improve this question
In start_end and end_time file, is each process time entry starts at new line ?? – AVJ Sep 27 '15 at 6:28
I would suggest adding %s (seconds since the epoch, 1970-01-01 00:00:00) immediately after each human readable date (or instead of human readable if they'll never be read by a human). then calculation is a simple subtraction of end time in secs - start time in secs. – cas Sep 27 '15 at 8:18
Are the Start time - and End time file lines actually in the files? – terdon Sep 27 '15 at 10:27

I agree with cas' comment above re proper logfile date to avoid it future reformatting as below

awk '
    "date +%s -d \""d" "$NF"\"" | getline m
    for(i in D)
        print "Process", i, "time :", D[i], "sec"
}' file

To save the ending order of processes just change the end of script to:

…       D[$5]=-m
        print "Process", $5, "time :", D[$5] + m
}' file
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.