master
md 26 lines 1.19 KB
Rendered Raw
1 # Session leader
2
3 A session leader is a linux process, which is forked from [init](init.md) after receiving a `LxInitMessageCreateSession` message (see `src/linux/init.cpp`)
4
5 ## Creating linux processes
6
7 Session leaders are used to create linux processes on behalf of the user. Each linux session leader is associated to a Windows console.
8
9 To create a user process, [wslservice.exe](wslservice.exe.md) sends a `LxInitMessageCreateProcess` message (WSL1) or a `LxInitMessageCreateProcessUtilityVm` message (WSL2), which contains details about the process to create such as:
10
11 - Command line
12 - Current directory
13 - Environment variables
14 - User name
15
16 ### Creating a WSL1 process
17
18 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:
19
20 - The user and group id
21 - The current directory
22 - The standard file descriptors (stdin, stdout, stderr)
23
24 ### Creating a WSL2 process
25
26 When running in a WSL2 distribution, the session leader forks() to create a [relay](relay.md) process, which is responsible for creating the user process and relaying its output back to [wsl.exe](wsl.exe.md)