linux-sysprog · beginner · ~15 min

Over the hard limit?

Detect a limit breach.

Challenge

Crossing a hard rlimit is what triggers enforcement (SIGXCPU, allocation failures). Detect whether usage has gone over.

Task

Implement int exceeds_limit(long current, long limit) that returns 1 if current is strictly greater than limit, else 0.

Input

  • current: current usage.
  • limit: the limit.

Output

1 if current > limit, else 0.

Example

exceeds_limit(101, 100)   ->   1
exceeds_limit(100, 100)   ->   0   (at the limit is allowed)
exceeds_limit(99, 100)    ->   0

Edge cases

  • Exactly at the limit: return 0 (not a breach).

Input format

current: current usage; limit: the limit.

Output format

1 if current > limit (strictly), else 0.

Constraints

Being exactly at the limit is not a breach.

Starter code

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.