读书笔记系列 - Operating Systems: Three Easy Pieces - Virtualization - Chapter 5: Process API
简介:
读书笔记系列 - Operating Systems: Three Easy Pieces - Virtualization - Chapter 5: Process API
5. Process API
- UNIX presents one of the most intriguing ways to create a new process with a pair of system calls:
fork()
and exec()
.
5.1 The fork()
System Call
- The fork() system call is used to create a new process.
- The CPU scheduler determines which process runs at a given moment in time.
5.2 The wait()
System Call
5.3 Finally, The exec()
System Call
- This
exec()
system call is useful when you want to run a program that is different from the calling program.
5.4 Why? Motivating The API
5.5 Process Control And Users
- Beyond fork(), exec(), and wait(), there are a lot of other interfaces for interacting with processes in UNIX systems.
- The kill() system call is used to send signals to a process, including directives to pause, die, and other useful imperatives.
5.6 Useful Tools
5.7 Summary
- Each process has a name; in most systems, that name is a number known as aprocess ID (PID).
- The fork() system call is used in UNIX systems to create a new process. The creator is called the parent; the newly created process is called the child. As sometimes occurs in real life, the child process is a nearly identical copy of the parent.
- The wait() system call allows a parent to wait for its child to complete execution.
- The exec() family of system calls allows a child to break free from its similarity to its parent and execute an entirely new program.
- A UNIX shell commonly uses fork(), wait(), and exec() to launch user commands; the sparation of fork and exec enables features like input/output redirection, pipes, and other cool features, all without changing anything about the programs being run.
- Process control is available in the form of signals, which can cause jobs to stop, continue, or even terminate.
- Which processes can be controlled by a particular person is encapsulated in the notion of a user; the operating system allows multiple users onto the system, and ensures users can only control their own processes.
- A super user can control all processes (and indeed do many other things); this role should be assumed infrequently and with caution for security reasons.