linux-sysprog · intermediate · ~15 min

Parse VmRSS from /proc status

Extract a labelled field from /proc text.

Challenge

Given the text of a /proc/<pid>/status file, implement long parse_vmrss_kb(const char *status) returning the VmRSS value in kB (the number after VmRSS:), or -1 if absent.

Starter code

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

long parse_vmrss_kb(const char *status) {
    /* TODO */
    return -1;
}

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