cybersecurity · beginner · ~15 min · safe pentest lab

Parent PID from status

Extract the parent PID specifically.

Challenge

Extract the parent PID from a /proc/<pid>/status text — following PPid links reconstructs the process tree during incident response.

Task

Implement int parse_ppid(const char *status) that returns the integer following "PPid:" in status, or -1 if that label is absent.

Input

  • status: a fixed /proc/<pid>/status-style text the grader provides.

Output

Returns the parent PID as an int, or -1 if "PPid:" is not present.

Example

parse_ppid("Name:\tx\nPPid:\t1234\n")   ->   1234
parse_ppid("Name:\tx\n")                 ->   -1   (no PPid)

Edge cases

  • "PPid:" absent: return -1.
  • Whitespace (tab or spaces) may separate the label from the value.

Input format

A fixed /proc//status-style text.

Output format

The integer after "PPid:", or -1 if absent.

Constraints

Find "PPid:", skip whitespace, parse the number.

Starter code

#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.