Process Concept n An operating system executes a

  • Slides: 19
Download presentation
Process Concept n An operating system executes a variety of programs F Batch system

Process Concept n An operating system executes a variety of programs F Batch system – jobs F Time-shared systems – user programs or tasks n Process – a program in execution n A process includes: F Text segment F Data segment F Stack segment F Program counter Operating System Concepts 4. 1 Silberschatz, Galvin and Gagne 2002

Process State n As a process executes, it changes state F new: The process

Process State n As a process executes, it changes state F new: The process is being created. F running: Instructions are being executed on the CPU. F waiting: The process is waiting for some event to occur. F ready: The process is waiting for the CPU. F terminated: The process has finished execution. Operating System Concepts 4. 2 Silberschatz, Galvin and Gagne 2002

Process Control Block (PCB) Information associated with each process. n Process state n Program

Process Control Block (PCB) Information associated with each process. n Process state n Program counter n CPU register values n CPU scheduling information n Memory-management information n Accounting information n I/O status information Operating System Concepts 4. 3 Silberschatz, Galvin and Gagne 2002

Process Queues n Job queue – set of all PCBs in the system. n

Process Queues n Job queue – set of all PCBs in the system. n Ready queue – set of all processes residing in main memory, ready and waiting to execute. n Device queues – set of processes waiting for a resource, e. g. , an I/O device. n PCBs migrate between the various queues. Operating System Concepts 4. 4 Silberschatz, Galvin and Gagne 2002

Ready Queue And Various I/O Device Queues Operating System Concepts 4. 5 Silberschatz, Galvin

Ready Queue And Various I/O Device Queues Operating System Concepts 4. 5 Silberschatz, Galvin and Gagne 2002

Context Switch n When the CPU switches to another process, the system must F

Context Switch n When the CPU switches to another process, the system must F F Switch to kernel mode Save the state of the old process Deal with the interrupt Load the saved state for the new process. n Hardware (and possibly OS) saves the state of the old process n The scheduler selects the new process n The dispatcher loads the new process F Set the PC F Switch to user mode n Context-switch time is overhead; the system does no useful work while switching F Time dependent on hardware support. Operating System Concepts 4. 6 Silberschatz, Galvin and Gagne 2002

CPU Switch From Process to Process Operating System Concepts 4. 7 Silberschatz, Galvin and

CPU Switch From Process to Process Operating System Concepts 4. 7 Silberschatz, Galvin and Gagne 2002

Process Creation n Parent process create children processes, which, in turn create other processes,

Process Creation n Parent process create children processes, which, in turn create other processes, forming a tree of processes. n Address space (one of) F Child duplicate of parent. F Child has a program loaded into it. n Execution (one of) F Parent and child execute concurrently F Parent waits until child terminates n Resource sharing (one of) F Parent and children share all resources. F Children share subset of parent’s resources. F Parent and child share no resources. Operating System Concepts 4. 8 Silberschatz, Galvin and Gagne 2002

Process Termination n Process executes last statement and tells the OS F Output status

Process Termination n Process executes last statement and tells the OS F Output status from child to parent F Process’ resources are (eventually) deallocated by the operating system n Parent may terminate execution of children processes F Child has exceeded allocated resources. F Task assigned to child is no longer required. F Parent is exiting 4 With cascading termination, the operating system does not allow child to continue if its parent terminates Operating System Concepts 4. 9 Silberschatz, Galvin and Gagne 2002

UNIX PCBs Operating System Concepts 4. 10 Silberschatz, Galvin and Gagne 2002

UNIX PCBs Operating System Concepts 4. 10 Silberschatz, Galvin and Gagne 2002

UNIX Shell Operating System Concepts 4. 11 Silberschatz, Galvin and Gagne 2002

UNIX Shell Operating System Concepts 4. 11 Silberschatz, Galvin and Gagne 2002

Threads n A thread (or lightweight process) is a basic unit of CPU utilization;

Threads n A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: F Program counter F Register set F Stack space n A thread shares with its peer threads its: F Code segment F Data segment F Operating-system resources n A traditional or heavyweight process is equal to a task with one thread. Operating System Concepts 4. 12 Silberschatz, Galvin and Gagne 2002

Single and Multithreaded Processes Operating System Concepts 4. 13 Silberschatz, Galvin and Gagne 2002

Single and Multithreaded Processes Operating System Concepts 4. 13 Silberschatz, Galvin and Gagne 2002

Thread Implementations n User-level threads library F POSIX Pthreads F Mach C-threads F Solaris

Thread Implementations n User-level threads library F POSIX Pthreads F Mach C-threads F Solaris threads n Kernel Threads F Windows 95/98/NT/2000 F Solaris F Linux Operating System Concepts 4. 14 Silberschatz, Galvin and Gagne 2002

Many-to-One n Many user-level threads mapped to single kernel thread. n Used on systems

Many-to-One n Many user-level threads mapped to single kernel thread. n Used on systems that do not support kernel threads. Operating System Concepts 4. 15 Silberschatz, Galvin and Gagne 2002

One-to-One n Each user-level thread maps to kernel thread. n Examples F Windows 95/98/NT/2000

One-to-One n Each user-level thread maps to kernel thread. n Examples F Windows 95/98/NT/2000 F OS/2 F Linux. Threads Operating System Concepts 4. 16 Silberschatz, Galvin and Gagne 2002

Many-to-Many Model n Allows many user level threads to be mapped to many kernel

Many-to-Many Model n Allows many user level threads to be mapped to many kernel threads. n Allows the operating system to create a sufficient number of kernel threads. F Solaris 2 F Windows NT/2000 with the Thread. Fiber package Operating System Concepts 4. 17 Silberschatz, Galvin and Gagne 2002

Pthreads n A POSIX standard (IEEE 1003. 1 c) API for thread creation and

Pthreads n A POSIX standard (IEEE 1003. 1 c) API for thread creation and synchronization. n API specifies behavior of the thread library, implementation is up to development of the library. n Common in UNIX operating systems. Operating System Concepts 4. 18 Silberschatz, Galvin and Gagne 2002

Benefits n Responsiveness F In a multiple threaded task, while one thread is blocked

Benefits n Responsiveness F In a multiple threaded task, while one thread is blocked and waiting, a second thread in the same task can run. F Kernel level threads provide a mechanism that allows sequential processes to make blocking system calls while also achieving parallelism. n Resource Sharing n Economy n Utilization of MP Architectures Operating System Concepts 4. 19 Silberschatz, Galvin and Gagne 2002