CPU usage limiting with setrlimit()

Hi all,

I hope this is the correct forum to ask this question. I have a question regarding process resource usage limitation via setrlimit() as it relates to RLIMIT_CPU. In the setrlimit manpage, it says the following about RLIMIT_CPU:


Code:
RLIMIT_CPU      The maximum amount of cpu time (in seconds) to be used by
                each process.

My question is, is this to be interpreted as total aggregate CPU usage time of the process or one-shot usage (i.e. if the process uses CPU for more than x secs uninterrupted, then send SIGXCPU)?

More concretely, the getty process sets a 60 second limit (GETTY_TIMEOUT=60) via below code, and I am trying to understand if getty will call timeoverrun signal handler when it has consumed 60 seconds of aggregate CPU time or 60 seconds at a single time.

Code:
/*
 * Limit running time to deal with broken or dead lines.
 */
(void)signal(SIGXCPU, timeoverrun);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = GETTY_TIMEOUT;
(void)setrlimit(RLIMIT_CPU, &limit);

Thank you in advance for you help in clarifying this point!

Raku
 
Yes, except for the "uninterrupted" part. The process runs and when its CPU time reaches the limit, it receives SIGXCPU.
 
Thanks, I verified it also by making a program. The CPU time is cumulative. Even if the process is interrupted, its CPU time is still aggregated and when it surpasses the set threshold, the signal is received.
 
What about child processes? Does child process CPU time count towards the limit, or does each child process get its own limit the same as the parent?
 
Back
Top