linux-sysprog · beginner · ~15 min
Detect a limit breach.
Crossing a hard rlimit is what triggers enforcement (SIGXCPU, allocation failures). Detect whether usage has gone over.
Implement int exceeds_limit(long current, long limit) that returns 1 if current is strictly greater than limit, else 0.
current: current usage.limit: the limit.1 if current > limit, else 0.
exceeds_limit(101, 100) -> 1
exceeds_limit(100, 100) -> 0 (at the limit is allowed)
exceeds_limit(99, 100) -> 0
current: current usage; limit: the limit.
1 if current > limit (strictly), else 0.
Being exactly at the limit is not a breach.
int exceeds_limit(long current, long limit) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.