Clarify why the child process is useful
This commit is contained in:
parent
fb132a4f0f
commit
1f4326fd68
1 changed files with 6 additions and 3 deletions
9
exec.c
9
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
|
||||
|
|
Loading…
Reference in a new issue