Expand upon the argument for

This commit is contained in:
Nick Chambers 2023-12-27 16:12:07 -06:00
parent 592ddbc2af
commit fb132a4f0f
1 changed files with 8 additions and 5 deletions

13
exec.c
View File

@ -13,8 +13,8 @@ int main() {
pid_t pid = fork();
// 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 (PID) of the
// child process.
// will be 0. In the parent process, `pid` will be the process ID (a non-0
// number) of the child process.
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
@ -26,10 +26,13 @@ int main() {
execvp(cmdline[0], cmdline);
} else {
// In the parent process, pause until the child process exits. The `wait`
// function takes a pointer to a structure that contains information about
// function takes a pointer to an integer that contains information about
// how the child process exited. If the exit information isn't necessary,
// `NULL` can be passed instead.
wait(NULL);
// `NULL` can be passed instead. Several macros are available to obtain
// further information about how the process exited.
int status = 0;
wait(&status);
printf("Process %d exited with status %d.\n", pid, status);
}
// The parent process is now finished, and will return the number `0` to