From fb132a4f0fbdd7e3631805aa2595bcc29d220bf6 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Wed, 27 Dec 2023 16:12:07 -0600 Subject: [PATCH] Expand upon the argument for --- exec.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/exec.c b/exec.c index 65097d9..98429e5 100644 --- a/exec.c +++ b/exec.c @@ -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