fork, exec, wait — the shape of a shell
fork, exec, wait — the shape of a shell
Answer
pid_t pid = fork(); if (pid == 0) { execl("/bin/date", "date", (char *)0); perror("execl"); _exit(127); } wait(NULL);
The child becomes date while keeping its PID; the parent blocks in wait() until it finishes. The two lines after execl run only if the exec failed.
S&K 3e ch19 §19.3.5 and ch17 §17.5, §17.7; the exec family per POSIX.1-2024