Docsity

Operating System: Process Management and Interprocess Communication, Study notes of Operating Systems

Partial preview of the text

Download Operating System: Process Management and Interprocess Communication and more Study notes Operating Systems in PDF only on Docsity!

Process Management

 OS becomes more complex in going from  Single to multi-programming system  Single user to time-sharing system.  A collection of processes executing user or OS codes exist  OS is responsible for all process management activities.

 Topics to be covered:

 Processes  Threads  CPU Scheduling  Process Synchronization  Deadlocks

Processes

Source: Operating System Concepts by Silberschatz, Galvin and Gagne

Process Concept

 A computer system executes a variety of programs:  OS programs – system calls  Batch system – jobs  Time-shared systems – user programs or tasks  Single-user systems – different application programs.  All these CPU activities are processes.  Textbook uses the terms job and process almost interchangeably.

What Is Process?

 Process – a program in execution:  is an active entity – a program is passive entity until it is in execution  is a unit of CPU work  executes OS and user codes  requires certain resources to do its task  supports a single or multiple threads.  A process includes:  Program counter and processor’s registers defining current activity  Stack, heap, data and text.

Process Control Block (PCB)

Information associated with each process is represented by PCB. Also called TCB.  Process state  New, ready, running, waiting, and terminated  Process number  pid  Program counter  Indicates the address of the next instruction to be executed for this process  CPU registers  Accumulators, registers, stack pointers  CPU scheduling information  Process priority, scheduling queue pointers  Memory-management information  Values of base and limit registers, page tables, etc.  Accounting information  CPU or real time used, time limits, account numbers, process numbers  I/O status information  List of I/O devices, list of files

CPU Switch From Process to Process

 PCB serves as the repository for any information that may vary from process to process.  The state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward.

Ready Queue And Various I/O Device Queues  Linked list: A queue header contains pointers to the first and final PCBs in the list. Each PCB is extended to include a pointer field that points to the next PCB in the queue.

Schedulers

 OS must select processes for scheduling purposes in some fashion carried out by an appropriate scheduler.  Two types of schedulers:  Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU  Deals with programs which are already brought to memory.  Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.  Major difference in the frequency of execution:  Short-term scheduler is invoked very frequently (milliseconds) ⇒ must be fast.  Long-term scheduler is invoked very infrequently (seconds, minutes) ⇒ may be slow.

Addition of Medium Term Scheduling

Medium-term scheduler also called swapping swaps processes out of memory and later swaps them into the memory. It thus reduces the degree of multiprogramming.

Context Switch

 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. This task is known as a context switch.  The context of a process is represented by PCB.  Context-switch time is overhead; the system does no useful work while switching.  This time is dependent on hardware support.  Switching speed depends on memory speed, number of registers that must be copied, and special instructions (such as single instruction to load or store all registers)  Typical speeds range from 1 to 1000 μs.  Switching time may be bottleneck for complex OS.

Process Creation

 Parent process can create children processes, which, in turn create other processes, forming a tree of processes.  Resource sharing  Parent and children share all resources.  Children share subset of parent’s resources.  Parent and child share no resources.  Initialization data  Passed along from parent to child process.  Execution  Parent and children execute concurrently.  Parent waits until children terminates.

Process Creation  Parent process creates children processes, which, in turn create other processes, forming a tree of processes.  A tree of processes on a typical Solaris system.

C Program Forking a Separate Process

int pid;

pid = fork ();

if (pid == 0) {

execlp (“/bin/ls”, “ls”, NULL);

else if (pid >= 0){

wait (NULL);

printf ("Child Complete");

exit (0);

Process Termination

 Normal: Process executes its final statement and ask the OS to delete it ( exit ).  Output data from child to parent (via wait ).  Process’ resources are deallocated by the OS.  Abnormal: Parent may terminate execution of children processes ( abort ).  Child has exceeded allocated resources.  Task assigned to child is no longer required.  Parent is exiting.  OS does not allow child to continue if its parent terminates.  Cascading termination - All children terminated.