linux-sysprog · beginner · ~15 min
Model the two-strike shutdown policy.
Many programs treat the first Ctrl-C as "shut down cleanly" and a second as "force quit now". Model that two-strike policy.
Implement int should_force_exit(int sigint_count) that returns 1 if sigint_count is 2 or more, else 0.
sigint_count: how many times SIGINT (Ctrl-C) has been received.1 if sigint_count >= 2, else 0.
should_force_exit(1) -> 0 (first Ctrl-C: graceful)
should_force_exit(2) -> 1 (second: force quit)
should_force_exit(5) -> 1
sigint_count: number of SIGINTs received.
1 if sigint_count >= 2, else 0.
First Ctrl-C is graceful; the second forces exit.
int should_force_exit(int sigint_count) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.