0

I have a program that runs 24/7 and collects resource information on a system. One of the requirements is to cause as little impact to the system as possible, so there are cpu checks to kill it if it starts using up too much cpu.

tl;dr version: I'd like my process to not add a specific child's process cpu time to the cutime field in /proc/[pid]/stat when reaped.

long version:

I use the utime/stime/cutime/cstime fields from /proc/[pid]/stat to monitor incremental cpu changes.

The program spawns many processes that should reflect in the cutime field.

However, the program also has an option to run some additional collection where it will spawn another long-running background process. Since it can run for hours or even days, what ends up happening is if the optional process is stopped, when it is reaped, the cutime/cstime fields will spike due to the accumulated cpu usage of the child process and make it appear that the main process is using significant amounts of cpu, triggering a watcher script to kill it.

The watcher script is a separate process.

I could switch to a more instantaneous cpu measure like what top would use (read cpu, wait a second, read cpu again) and then it would be unlikely for the process death to occur during the sample, but I was wondering if there is just a way to exclude the child process cpu from being added to cutime when reaped.

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.