linux-sysprog · beginner · ~15 min

Count pipeline stages

Relate pipe symbols to process count.

Challenge

Implement int pipeline_stages(const char *cmd) returning the number of commands in a pipeline — the number of '|' characters plus one. An empty string has 0 stages.

Starter code

int pipeline_stages(const char *cmd) {
    /* TODO */
    return 0;
}

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