5.4 Why? Motivating The API
- The separation of fork() and exec() lets the shell run code after the call to fork() but before the call to exec()
-> The shell shows a prompt and the user types a command; -> The shell finds where in the file system the executable resides; -> The shell creates a fork() and then exec() the command typed in the prompt; -> The shell waits for the command to complete by using wait(); -> The shell prints the prompt again;
- pipe() -> the output of one process is connected to an internal kernel pipe (Queue) and the input of another to that same pipe. The output of one process seamlessly is used as input to the next.
5.5 Process Control And Users
- SIGINT (interrup) -> control-c
- SIGTSTP (stop) -> control-z
- fg -> might continue a process
-> signal() -> catches signals so when a particular signal is delivered to a process, it will suspend it's normal execution and run a particular piece of code in response to the signal.
-> Users generally can only control their own processes. -> The OS parcels the resources (CPU, memory, disk) to each user(and their process)
5.6 Useful Tools
ps -> see running processes top -> display the processes of the system and how much CPU and other resources they are eating up
5.7 Summary
- Each process has a name; in most systems, that name is a number known as a process ID (PID)
- The fork() system call is used in UNIX systems to create a new process. The creator is called the parent; the newly to created process is called a child. As sometimes occurs in real life, the child process is 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 call allows a parent to wait for its child to complete execution;
- A UNIX shell commonly uses fork(), wait() and exec() to launch user commands; The separation of fork and exec enables features like input/output redirection, pipes, and other cool features, all without changing anything about 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 OS allows multiple users onto the system, and ensures users can only control their own processes.
- A superuser can control all processes (and indeed do many other things); this role should be assumed infrequently and with caution for security reasons.