cybersecurity · beginner · ~15 min · safe pentest lab
Extract the parent PID specifically.
Extract the parent PID from a /proc/<pid>/status text — following PPid links reconstructs the process tree during incident response.
Implement int parse_ppid(const char *status) that returns the integer following "PPid:" in status, or -1 if that label is absent.
status: a fixed /proc/<pid>/status-style text the grader provides.Returns the parent PID as an int, or -1 if "PPid:" is not present.
parse_ppid("Name:\tx\nPPid:\t1234\n") -> 1234
parse_ppid("Name:\tx\n") -> -1 (no PPid)
"PPid:" absent: return -1.A fixed /proc/
The integer after "PPid:", or -1 if absent.
Find "PPid:", skip whitespace, parse the number.
#include <string.h>
#include <stdlib.h>
int parse_ppid(const char *status) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.