Overview

In Lecture 04 we explore the intricacies of process creation and management in UNIX systems, focusing on the critical fork() and exec() functions. The lecture begins by explaining how fork() is used to create a new child process, duplicating the parent process's environment, while exec() replaces the current process image with a new program image, enabling dynamic execution paths. Through example programs, the lecture demonstrates the use of these functions, highlighting the non-deterministic scheduling of parent and child processes, the importance of checking return values to determine process identities, and the process state transitions leading to the creation of zombie processes and their reaping by the operating system or shell.

Additionally, the lecture delves into the nuances of including header files, the entry point of processes, and the handling of standard I/O streams, illustrating how processes interact with the system and each other. It also covers advanced topics such as process waiting, error checking, context switching, and I/O redirection, showcasing how a child process can redirect its output to a file before being replaced by a new program image through execvp. The motivation behind the UNIX process API design is discussed, emphasizing its significance in building a UNIX shell and enabling shell functionalities like environment manipulation before program execution. This comprehensive overview provides a deep understanding of process creation, management, and communication in operating systems, setting the stage for further exploration of system-level programming and shell implementation.

Assigned Reading

Assigned Videos

None at this time.

Slides

Original slides:

https://docs.google.com/presentation/d/11JGWHD8NUVhSFklK-tbdxCwqFB2K4atTG-1JphOd8xo/edit?usp=sharing

2024 slides:

https://docs.google.com/presentation/d/1gQ2htEN6pHJWpIutwcuS--c_7UCN1SCE-fQy5fp1lyk/edit?usp=sharing

Example Code

References / Resources

  1. fork()
  2. exec()
  3. wait()
  4. waitpid()