linux-sysprog · beginner · ~15 min
Apply a resource ceiling.
A process may use a resource up to its soft rlimit; requests above it are capped. Apply that ceiling.
Implement long clamp_to_limit(long want, long soft_limit) that returns want capped at soft_limit — that is, the smaller of the two.
want: the requested amount.soft_limit: the resource ceiling.min(want, soft_limit).
clamp_to_limit(50, 100) -> 50
clamp_to_limit(150, 100) -> 100
clamp_to_limit(100, 100) -> 100
want: requested amount; soft_limit: ceiling.
The smaller of want and soft_limit.
long clamp_to_limit(long want, long soft_limit) {
/* TODO */
return want;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.