linux-sysprog · intermediate · ~15 min

Parse thread count

Reuse the labelled-field parsing pattern.

Challenge

From the same /proc/<pid>/status text, implement int parse_threads(const char *status) returning the integer after Threads:, or -1 if absent.

Starter code

#include <string.h>
#include <stdlib.h>

int parse_threads(const char *status) {
    /* TODO */
    return -1;
}

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