Context-switch time is overhead; ° ± system does no useful work while switching ± can become a bottleneck ° Time for context switch is dependent on hardware support ( 1- 1000 microseconds).
Process Creation ° Processes are created and deleted dynamically ° Process which creates another process is called a parent process; the created process is called a child process. ° Result is a tree of processes ° e.g. UNIX - processes have dependencies and form a hierarchy. ° Resources required when creating process ° CPU time, files, memory, I/O devices etc.
UNIX Process Hierarchy
Process Creation ° Resource sharing ± Parent and children share all resources. ± Children share subset of parent’s resources - prevents many processes from overloading the system. ± Parent and children share no resources. ° Execution ± Parent and child execute concurrently. ± Parent waits until child has terminated. ° Address Space ± Child process is duplicate of parent process. ± Child process has a program loaded into it.
UNIX Process Creation ° Fork system call creates new processes ° execve system call is used after a fork to replace the processes memory space with a new program.
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 deallocated by operating system. ° Parent may terminate execution of child processes. ± Child has exceeded allocated resources. ± Task assigned to child is no longer required. ± Parent is exiting ² OS does not allow child to continue if parent terminates ² Cascading termination
Threads ° Processes do not share resources well ± high context switching overhead ° A thread (or lightweight process) ± basic unit of CPU utilization; it consists of: ² program counter, register set and stack space ° A thread shares the following with peer threads: ² code section, data section and OS resources (open files, signals) ° Collectively called a task. ° Heavyweight process is a task with one thread.
Single and Multithreaded Processes
Benefits ° Responsiveness ° Resource Sharing ° Economy ° Utilization of MP Architectures
Threads(Cont.) ° In a multiple threaded task, while one server thread is blocked and waiting, a second thread in the same task can run. ° Cooperation of multiple threads in the same job confers higher throughput and improved performance. ° Applications that require sharing a common buffer (i.e. producer-consumer) benefit from thread utilization. ° Threads provide a mechanism that allows sequential processes to make blocking system calls while also achieving parallelism.
Threads (cont.) ° Thread context switch still requires a register set switch, but no memory management related work!! ° Thread states - ° ready, blocked, running, terminated ° Threads share CPU and only one thread can run at a time. ° No protection among threads.
Threads (cont.) ° Kernel-supported threads (Mach and OS/2) ° User-level threads ° Hybrid approach implements both user-level and kernel-supported threads (Solaris 2).
User Threads ° Thread management done by user-level threads library ° Supported above the kernel, via a set of library calls at the user level.
- One '20