📜 ⬆️ ⬇️

A real-life challenge: How to restore a process tree in Linux

We are developing a CRIU project (Checkpoint / Restore in Userspace) and we have a rather interesting task on how to restore the original process tree. I suggest you try to solve it.

Task


CRIU is a utility that allows you to save the state of processes to disk and resolve them later on this or any other machine. One of the recovery subtasks is to find a sequence of actions to restore the process tree. Input data contains a set of parameters for each process: a unique identifier (PID), a reference to the parent (PPID), a session identifier (SID).

image

')

The rules by which live processes in Linux




Commands:




Sample input


Input data contains a line for each process. Each line contains 3 numbers pid, ppid (parent's pid), sid and zombie flag, which is 0 - if the process is dead (zombies), and 1 - if the process is live.

1 0 1 1
6 1 6 1
8 6 7 1
15 6 12 1
10 1 10 1
11 10 7 1
13 10 12 1

Sample output


1: fork (6)
6: fork (7)
7: setsid ()
7: clone (8, CLONE_PARENT)
7: exit ()
6: wait ()
8: fork (9)
9: fork (10)
10: fork (11)
10: fork (12)
12: setsid ()
12: clone (13, CLONE_PARENT)
12: clone (14, CLONE_PARENT)
12: exit ()
10: wait (12)
14: fork (15)
6: prctl (PR_SET_CHILD_SUBREAPER, 1)
14: exit ()
10: wait (14)
6: prctl (PR_SET_CHILD_SUBREAPER, 0)
9: exit ()
8: wait (9)
6: setsid ()
10: setsid ()

Source: https://habr.com/ru/post/195330/


All Articles