Help with prlimit

Michael Kerrisk mtk.manpages@gmail.com
Sat Mar 18 11:51:00 GMT 2017


On Fri, Mar 17, 2017 at 4:12 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On 22 Jan 2017 22:36, Vasantha Ganesh wrote:
>>   prlimit used with RLIMIT_CPU sends SIGXCPU to the process whose pid
>> was mentioned as an argument (subprocess). I would like it if the
>> parent process were the one who received the SIGXCPU or any other
>> custom signal, then the parent process can decide what to do with that
>> subprocess. Like it can suspend it or kill it, things like that. To
>> create such a function what part of the code-base should I read or
>> work on? I don't have control over what subprocess I'm going to run so
>> I want to give a couple of subprocess a fixed equal amount of time for
>> execution. I believe I have to hack on with prlimit to achieve this.
>
> all of the rlimit logic is in the kernel.  glibc merely provides an API
> to users to easily call into it.
>
> if you want to limit CPU utilization, you might want to look into control
> groups instead.  which is also outside of glibc ;).

And another possibility is to employ a timer that counts according to
the CPU time consumed by another process. Use clock_getcpuclockid() to
get the CPU clock of another process, and feed that to timer_create(),
and arm your timer with suitable values using timer_settime(). When
you measure that the process has consumed CPU up to the limit, send it
a signal.

Cheers,

Michael



More information about the Libc-help mailing list