linux-sysprog · intermediate · ~15 min

Decode an exit status

Decode the wait status bitfield.

Challenge

wait fills a status word. Emulate WEXITSTATUS: implement int exit_code(int wstatus) returning the child's exit code, which is bits 8-15 of wstatus ((wstatus >> 8) & 0xFF).

Starter code

int exit_code(int wstatus) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.