1. Definition
- Process: a program in execution
- process execution must progress in sequential fashion
- A program is a passive entity, whereas a process is an active entity with a program counter and a set of associated resources.
- Each process has its own address space
- Text section (text segment) contains the executable code
- the program counter and CPU registers are part of the process context.
- Data section (date segment) contains the global variables
- Stack contains temporary data (local variables, return addresses...)
- A process may contain a heap, which contains memory that is dynamically allocated at run-time
2. OS requirements for processes
- OS must interleave the execution of several processes to maximize CPU usage while providing reasonable response time
- OS must allocate resources to processes while avoiding deadlock
- OS must support inter process communication and user creation of process.
3. A simple implementation of processes
- The process index register contains the index into the process list of the currently executing process (B)
- A process switch from B to A consist of storing (in memory) B's context and loading (in CPU registers) A's context
- A data structure that provides flexibility (to add new features)
4. Process Creation
- Principal events that cause process creation
- system initialization
- execution of a process creation system call by a running process
- user request to create new process
- Parent process creates child processes, which, in turn create other processes, forming a tree (hierarchy) of processes.
- Issues
- will the parent and child execute concurrently
- how will the address space of the child be related to the parent?
- will the parent and child share some resources?
5. An example Process
6. Process Creation in Unix
- Each process has a process identifier (pid)
- The parent executes fork() system call to spawn a child
- The child process has a separate copy of the parent's address space
- Both the parent and the child continue execution at the instruction following the fork() system call
- Typically, the child executes a system call like execlp() to load a binary file into memory
8. Process Termination
- process executes lat statement and asks the operating system to delete it (exit)
- output data from child to parent (via wait or waitpid)
- process' resources are deallocated by operating system
- parent may terminate execution of children processes
- e.g., TerminationProcess() in Win32()
- process may also terminate due to errors
- cascading termination: when a system does not allow a child process to continue after the parent has terminated
9. Process States
- Running states
- Ready states
- Blocked states
- New state
- os has performed the necessary actions to create process but has not yet admitted the process
- Exit state
- termination moves the process to this state
- tables and other info are temporarily preserved for auxiliary program
10. Swapping/Suspending
- Processes may need to be swapped out to disk
- this is true even with virtual memory
- 2 new states
- blocked suspend: blocked processes which have been swapped out to disk
- ready suspend: ready processes which have been swapped out to disk
11. Process Scheduling
- The operating system is responsible for managing the scheduling activities
- a uniprocessor system can have only one running process at a time
- the main memory cannot always accommodate all processes at run-time
- The operating system will need to decide on which process to execute next (CPU scheduling), and which processes will be brought to the main memory (job scheduling)
12. Process Scheduling Queues
- Job queue: set of all processes in the system
- Ready queue: set of processes residing in the main memory, ready and waiting for CPU
- Device queue: set of processes waiting for an I/O device
- Process migration is possible among these queues
13. Schedulers
- The processes may be first spooled to a mass-storage system, where they are kept for later execution
- The long-term scheduler (or job scheduler)
- selects processes from this pool and loads them into memory for execution
- the long term scheduler, if it exists, will control the degree of multiplexing
- The short-term scheduler (or CPU scheduler)
- selects from among ready processes, and allocates the CPU to one of them
- unlike the long-term scheduler, the short-term scheduler is invoked very frequently
14. CPU and I/O burts
- CPU-I/O burst cycle
- process execution consist of a cycle of CPU execution and I/O wait
- I/O bound process
- sends more time doing I/O than computations, many short CPU bursts
- CPU-bound process
- sends more time doing computation, few very long CPU bursts
No comments:
Post a Comment