# ReaperRun A simple wrapper that adds `PR_SET_CHILD_SUBREAPER` flag to a program. ## Background i3wm can start daemons and programs (e.g. `nm-applet` and `xterm`), but it doesn't set the subreapper flag. Since Linux 3.14, service managers can use this flag to act as "init", reaping orphan children. i3wm starts processes (the `exec` command in configuration file) by double-forking, and the intermediate fork immediately exits after forking the child, making the children orphan. systemd-user uses this flag to reap orphan children, but i3wm is not started using systemd-user but a display manager (e.g. SDDM in my case). SDDM does not set this flag as well, making all processes under i3 reaped by init (1). This messes up the process tree. Read more: * [https://github.com/i3/i3/issues/4274](https://github.com/i3/i3/issues/4274) * [https://blog.lilydjwg.me/2014/2/23/let-s-adopt-orphaned-processes.43035.html](https://blog.lilydjwg.me/2014/2/23/let-s-adopt-orphaned-processes.43035.html) The trick is simple: Just add the subreaper flag to i3 or any of its parents. According to prctl(2), this flag will be preserved across execve(2), so it is best to make a wrapper to set the flag and exec i3 rather than patching i3. ## Usage 1. Run `make release`. The output is `main`. 2. Ask your display manager to run `/path/to/reapperrun /path/to/i3` instead of running i3 directly. That's it. ## Effect Tree of init before: ``` at-spi-bus-laun,768 --launch-immediately |-dbus-daemon,781 --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3 at-spi2-registr,8096 --use-gnome-session blueman-applet,8059 /usr/bin/blueman-applet blueman-tray,8110 /usr/bin/blueman-tray chromium,8485 fcitx5,8064 i3bar,8048 --bar_id=bar-0 --socket=/run/user/10001/i3/ipc-socket.8025 keepassxc,8073 fish,6582 nm-applet,8061 i3,8025 telegram-deskto,8248 xterm,8119 ``` Tree of init after: ``` i3,9348 |-blueman-applet,9381 /usr/bin/blueman-applet |-blueman-tray,9433 /usr/bin/blueman-tray |-fcitx5,9391 |-i3bar,9371 --bar_id=bar-0 --socket=/run/user/10001/i3/ipc-socket.9348 |-keepassxc,9395 |-nm-applet,9383 `-xterm,9436 ``` You can see that all processes are under i3 now.