Created
March 19, 2015 12:19
-
-
Save onyb/4cb1e171b7db07dfd6d9 to your computer and use it in GitHub Desktop.
Operating Systems (Third Edition): Chapter 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operating Systems (Third Edition) | |
Harvey M. Deitel, Paul J. Deitel, David R. Choffnes | |
------------------------------------------------------------------------------- | |
CHAPTER 3: Process Concepts | |
------------------------------------------------------------------------------- | |
# Definition of Process | |
- A process is a program in execution. | |
- A process has its own address space consisting of the segments: | |
* Text: stores the machine code to be executed. | |
* Data: stores variables and dynamically allocated memory (heap). | |
* Stack: stores instructions and local variables for function calls. | |
# Process States | |
- A process can be in one of the following discrete states: | |
* Running: the process is currently being executed. | |
* Ready: the process is ready to be executed if the processor becomes | |
available. | |
* Blocked: the process is waiting for some event to happen | |
(eg. I/O completion event) before it can proceed. | |
- OS maintains a ready list and a blocked list for storing references to | |
processes which are not running. | |
- The ready list is typically a priority queue. The next process to receive | |
the processor is the one with the highest priority. | |
- The blocked list is usually unordered, i.e. unblock in the order in which | |
the events they are waiting for occur. | |
- In some special cases, a blocked list can be prioritized when several | |
processes are waiting for the same event. | |
# Process management | |
- create process | |
- destroy process | |
- suspend process | |
- resume process | |
- change process priority | |
- block process | |
- wake up process | |
- dispatch process | |
- Interprocess Communication (IPC) | |
# Process State Transition | |
- The act of assigning a processor to the first process on the ready list | |
is called dispatching. | |
- OS may use an interval timer to allow a process to run for a specific | |
time interval or quantum. | |
- If a running process initiates an I/O operation before its quantum | |
expires, and therefore must wait for the I/O operation to complete | |
before it can use a processor again, the running process voluntarily | |
relinquishes the processor. | |
- Four possible state transitions: | |
* When a process is dispatched, it transitions from ready to running. | |
* When the time quantum expires, it transitions from running to ready. | |
* When a process blocks, it transitions from running to blocked. | |
* When the event occurs (or, I/O operation completes), it transitions | |
from blocked to ready. | |
# Process Control Block (PCB) | |
- Also known as Process Descriptor, it contains: | |
* Process Identification Number (PID) | |
* Process state | |
* Program counter | |
* Scheduling priority | |
* Credentials | |
* A pointer to process's parent | |
* Pointers to process's children | |
* Pointers to locate the data and instructions in memory | |
* Pointers to allocated resources | |
- The OS maintains pointers to each process's PCB in a system-wide or | |
per-user process table. | |
- Allows for quick access to PCBs. | |
- When a process is terminated, the OS removes the process from the process | |
table and frees all of the process's resources. | |
# Process Operations | |
- A process may spawn a new process. The creating process is parent and the | |
created process is the child. | |
- A child can have only a single parent. | |
- When a parent process is killed, OS can responds in two ways: | |
* Destroy all child processes of that parent. | |
* Allow child process to proceed independently of the parent. | |
# Process Hierarchy in Linux | |
init | |
├── khubd | |
├── klod | |
├── kswapd | |
├── login | |
│ └── bash | |
│ ├── finger | |
│ ├── myprog | |
│ └── vi | |
├── pdflush | |
└── xfs | |
# Suspend and Resume | |
- Useful for detecting security threats and debugging. Processes may be | |
suspended rather than aborting. | |
- A suspension may be initiated by the process being suspended or by | |
another process. | |
- A suspended process must be resumed by another process. | |
- Two suspended states - suspended ready, and suspended blocked. | |
# Context Switching | |
- Stop executing a running process, and give processor to a ready process. | |
- Before a context switch, the current execution context of the running | |
process is saved in its PCB. Execution context of the ready process is | |
loaded from its respective PCB as well. | |
- OS must minimize context-switching time. | |
- Performed in hardware by some architectures. | |
# Interrupts | |
* Synchronous interrupt | |
- Such an interrupt is generated as a result of executing a process's | |
instructions. | |
- Also known as a trap. | |
- Eg. dividing by zero, referencing protected memory location. | |
* Asynchronous interrupt | |
- Caused by some event that is unrelated to a process's current | |
instruction. | |
- Eg. keyboard generates an interrupt when a key is pressed. | |
- Polling approach - processor repeatedly requests the status of each | |
device, hence increased overhead. | |
* Handling interrupts | |
- After receiving an interrupt, the processor completes execution of | |
the current instruction, then pauses the current process. Processor | |
will then execute one of kernel's interrupt handling functions. | |
- Interrupt handlers are stored in an array of pointers called | |
interrupt vector. | |
- After the interrupt handler completes, the interrupted process is | |
restored and executed, or the nexr process is executed. | |
* IA-32 Interrupt classes | |
- I/O: they notify a processor that status of an I/O device has changed. | |
- Timer: a system may contain devices that generate interrupts | |
periodically. Timers enable the OS to determine if a the time quantum | |
of a process has expired. | |
- Interprocessor interrupts: allows one processor to send message to | |
another processor, in a multiprocessing environment. | |
* IA-32 Exception classes | |
- Fault: an error that an exception handler can correct. After the | |
problem is corrected, the processor restarts the process at the | |
instruction that caused the exception. Eg, pagefault. | |
- Traps: class of uncorrectable errors. After executing a trap's | |
exception handler, the processor restarts the process at the next | |
instruction following the one that caused the exception. | |
Eg. overflow errors. | |
- Abort: Indicate errors from which the process or even the system | |
cannot recover, such as a hardware failure. | |
# Interprocess Communication (IPC) | |
* Singals | |
- Software interrupts that notify a process that an event has occurred. | |
- Does not allow processes to exchange data. | |
- Processes may catch, ignore, or mask (disable) a signal. | |
* Message passing | |
- Message passing between processes can be bidirectional. They can be | |
blocking or non-blocking. | |
- Blocking requires the receiver to notify the sender when the message | |
is received. | |
- Non-blocking enables the sender to continue with other work. | |
- Popular implementation is a pipe. It is a region of memory protected | |
by the OS that serves as a buffer allowing two or more processes to | |
exchange data. | |
# UNIX Processes | |
- All processes are provided with a set of memory addresses called virtual | |
address space. | |
- All processes interact with the OS via system calls. | |
- fork() syscall is used to spawn a child process. The child process | |
receives a copy of the parent process's data, stack segments, and any | |
other resources. Immediately following the fork(), the parent and the | |
child process contain identical data and instructions. | |
- After a fork() syscall, the parent process receives the PID of the child | |
and the child receives the value zero. Application programmers use this | |
convention to specify new instructions for the child to execute. | |
- If parent process is terminated by kill signal, it is also sent to all | |
the children. | |
- Process priorities are integers between -20 and 19 (inclusive). A lower | |
numerical priority indicates higher scheduling priority. | |
- Kernel processes often have negative priorities. | |
- Processes performing maintenance operations periodically, called daemons | |
execute with the lowest possible priority. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment