doc/docs/technical-documentation/session-leader.md
A session leader is a linux process, which is forked from init after receiving a LxInitMessageCreateSession message (see src/linux/init.cpp)
Session leaders are used to create linux processes on behalf of the user. Each linux session leader is associated to a Windows console.
To create a user process, wslservice.exe sends a LxInitMessageCreateProcess message (WSL1) or a LxInitMessageCreateProcessUtilityVm message (WSL2), which contains details about the process to create such as:
When running in a WSL1 distribution, the session leader forks(), and uses the child process to exec() into the user linux process. Before calling exec(), child configures various settings such as:
When running in a WSL2 distribution, the session leader forks() to create a relay process, which is responsible for creating the user process and relaying its output back to wsl.exe