From 1f4326fd68bed06fcf74694d8e091bc3a1c67ea9 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Mon, 4 Mar 2024 12:44:22 -0600 Subject: [PATCH] Clarify why the child process is useful --- exec.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exec.c b/exec.c index 98429e5..17944a1 100644 --- a/exec.c +++ b/exec.c @@ -14,10 +14,13 @@ int main() { // When the child process returns from `fork`, the value assigned to `pid` // will be 0. In the parent process, `pid` will be the process ID (a non-0 - // number) of the child process. + // number) of the child process. It is important to note that the process ID + // of the child isn't actually 0. The call to `fork` only returns 0 to + // allow code to determine if it is the child. if(pid == 0) { - // This call to `exec` will only be run by the child process. This is - // because `exec` replaces the process' instructions with the instructions + // Since this block only executes if `pid` is 0, the call to `execvp` will + // only be run by the child process. This is done because the `exec` family + // of functions replace the process' instructions with the instructions // found in `cmdline[0]` (in this case, `echo`). The `v` in `execvp` means // vector, which in this case refers to the array `cmdline`. The `p` means // path, indicating that it will search all of the directories found in the