For a process management,I would need to remove a process that exceeds a certain amount of CPU time, for example 1 hour.In PS command ,it has TIME parameter shows the total CPU time of a process .So is this the correct way to take the CPU time of a process? Also is there any other commands that could be used in calculating CPU time of process.
On most systems, you can use the
You can refine further by setting a soft limit after which the program receives the
I don't know of any shell utility to change the limit of a running program. You can cause the process to execute the
Depending on the precision you need, invoking
However, keep in mind that ps gets its data from somewhere; there's nothing magical about that particular application.
Have a look at
To get a more useful value (milliseconds), take the reported value and divide it by 1,000,000.
There are probably other ways to get the same data, but it might be non-trivial without resorting to syscalls into the kernel, which is not an easy thing to do from a shell script.