OS Lecture2
OS Lecture2
PROCESSES
Process Concept
Process Scheduling
Operations on Processes
Objectives
3
Multiple parts
The text section comprises the compiled program code, read in
from non-volatile storage when the program is launched.
It also includes the current activity, as represented by the value of
the program counter and the contents of the processor’s
registers.
A Stack containing temporary data
Function parameters, return addresses, local variables
Data section containing global variables
Heap containing memory dynamically allocated during run time
6
CPU registers -- The registers vary in number and type, depending on the
computer architecture
CPU-Scheduling information - Such as priority information and pointers to
scheduling queues.
Memory-Management information - E.g. page tables or segment tables.
Accounting information - This information includes the amount of CPU and real
time used, time limits, account numbers, job or process numbers, and so on.
I/O Status information - This information includes the list of I/O devices allocated
to the process, a list of open files, and so on.
CUSIT 2015
Process Control Block (PCB)
12
CPU Switch From Process to Process
13
Process Scheduling
14
When CPU switches to another process, the system must save the state of
the old process and load the saved state for the new process via a context
switch.
Process Creation
During the course of execution, a process may create several new
processes. The creating process is called a parent process, and the new
processes are called the children of that process. Each of these new
processes may in turn create other processes, forming a tree of processes.
Process identified and managed via a process identifier (pid)
Resource sharing
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate
Process Creation (Cont.)
21
Address space
Child duplicate of parent
The child process has a new program loaded into it.
UNIX examples
fork system call creates new process
exec system call used after a fork to replace the process’
memory space with a new program
Process Creation
22
A Tree of Processes on Solaris
23
24
Process Termination
Process executes last statement and asks the operating system to
delete it (exit)
Output data from child to parent (via wait)
Process’ resources are reallocated by operating system