cybersecurity · intermediate · ~15 min · safe pentest lab

Parse a labelled /proc field

Generalise the find-label-then-number recipe.

Challenge

Implement long proc_field(const char *status, const char *label) returning the integer after the label in a /proc/<pid>/status-style text, or -1 if absent. label includes its trailing colon, e.g. "PPid:".

Starter code

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

long proc_field(const char *status, const char *label) {
    /* TODO */
    return -1;
}

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