Terminate a Process and All of Its Descendant Processes
Last updated: November 29, 2026
Quick Overview
You are given parallel arrays pid and ppid, where ppid[i] is the parent of process pid[i] (0 means no parent), and a target pid to kill. Return every process id that will be terminated, since killing a process also kills all of its descendants.
Meta
November 29, 20260
0
0 solved
You are given parallel arrays pid and ppid, where ppid[i] is the parent of process pid[i] (0 means no parent), and a target pid to kill. Return every process id that will be terminated, since killing a process also kills all of its descendants.
A Meta phone screen style question rooted in fleet tooling, where a supervisor kills a service and everything it spawned. The interviewer checks that you invert the parent pointers into a child map once and then traverse, rather than scanning the arrays repeatedly.
What the Interviewer Expects
- Build a parent to children adjacency map in one pass
- Traverse with BFS or an explicit stack to avoid recursion limits
- Include the target itself in the output
- State O(n) time and space
- Handle a target with no children or that does not exist
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if the process table can contain a cycle because of corrupted data?
- How would you kill processes bottom-up so children die before parents?
- How would this work across machines where child processes live on remote hosts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
pid,ppidof equal length, andkill. ppid[i] == 0marks a root.- Output: all pids removed when
killis terminated, includingkill. Order does not matter....
High-Level Design
The parent array describes a forest. Scanning ppid for children of each killed process would be O(n^2). Instead, build children[parent] -> list of pids once, then do a BFS from kill. Every nod...