From f8322dd5fed971a0cdb714851417a3f29ead164a Mon Sep 17 00:00:00 2001 From: Morgan Date: Sun, 26 Nov 2023 07:55:55 +0000 Subject: [PATCH] =?UTF-8?q?Update=20Post=20=E2=80=9C2023-11-26-kernel-crea?= =?UTF-8?q?tion-of-new-process=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../posts/2023-11-26-kernel-creation-of-new-process.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/posts/2023-11-26-kernel-creation-of-new-process.md b/content/posts/2023-11-26-kernel-creation-of-new-process.md index 83f3fc6..275e9d8 100644 --- a/content/posts/2023-11-26-kernel-creation-of-new-process.md +++ b/content/posts/2023-11-26-kernel-creation-of-new-process.md @@ -1,7 +1,7 @@ --- -title: Kernel, creation of new process +title: Kernel, Process creation date: 2023-11-26T07:44:51.449Z -slug: kernel-new-process-creation +slug: kernel-process-creation description: "Deep dive Linux Kernel #3" --- ```c @@ -41,6 +41,8 @@ static int init(void * unused) } ``` -At `open("/dev/console") is opens fd 0, and with two `dup(0)`, fd 0, 1, 2 as stdin, stdout, stderr opens. When `execve()` or `fork()` happens, it simply copies calling process's `task_struct` as process context, so all file descriptors are also passed down. +In this `init/main.c`, after basic kernel initialization things, `open("/dev/console")` and two `dup(0)` opens three file descriptor 0, 1, 2 as stdin, stdout, stderr. Later when `execve()` or `fork()` happens, it simply copies calling process's `task_struct` as process context, so all file descriptors are also passed down as-is. -All processes' file descriptor 0, 1, 2 are all originates to `init`'s file descriptor, set up like above. +All processes' file descriptor 0, 1, 2 originates to `init`'s file descriptor. + +If calling process opens PTY or TTY, which is common when we opens new terminal to run a process, it is also passed down to exec/forked process.