linux-sysprog · intermediate · ~15 min

Bytes left in a pipe

Track pipe occupancy as a producer/consumer count.

Challenge

Model a byte pipe from an op string: 'w' writes one byte, 'r' reads one byte (ignored if the pipe is empty). Implement int pipe_bytes_available(const char *ops) returning how many bytes remain at the end.

Starter code

int pipe_bytes_available(const char *ops) {
    /* TODO */
    return 0;
}

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