I would like to avoid doing this by launching the process from a monitoring app.
|
Where The So it's convenient that |
||||
|
|
|
Portable:
i.e. that shell was started on January 30 and totaled about 6 seconds of CPU time. There may be more precise or more parseable but less portable ways to get this information. Check the documentation of your Under Linux, this information lives in
The CPU time is in jiffies; I don't know offhand how to find the jiffy value from the shell. The start time is relative to the boot time (found in |
|||||
|
|
Thus you can run this to get the PID and elapsed time of every process:
If you want the elapsed time of a particular PID (e.g. 12345), you can do something like:
(Edit: Turns out there's a shorter syntax for the above command; see mattdm's answer) |
|||
|
|
|
If you can run time and then execute a command you will get exactly what you are looking for. You cannot do this against an already-running command. [0] % time sleep 20 sleep 20 0.00s user 0.00s system 0% cpu 20.014 total |
|||
|