Process concept Concept of Multiprogramming n When there
- Slides: 40
Process concept
Concept of Multiprogramming n When there is a single program running in the CPU, it leads to the degradation of the CPU utilization. n Example: When a running program initiates an I/O operation, the CPU remain idle until the I/O operation is completed. Solution to this problem is provided by Multiprogramming.
Multiprogramming Continued. . Definition: A mode of operation that provides for the interleaved execution of two or more programs by a single processor.
Multiprogramming Continued. . Improving CPU utilization By allowing several programs to reside in main memory at the “same time” the CPU might be shared, such that when one program initiates an I/O operation, another program can be assigned to the CPU, thus the improvement of the CPU utilization.
Multiprogramming Continued. . Implementation The concept of process need to be introduced in order to understand multiprogramming and the concurrent execution of sequential processes in a computer system. What is a process?
Process n Definition: Ø Ø A program in execution An asynchronous activity The “locus of control” of a procedure in execution It is manifested by the existence of a process control block (PCB) in the operating system.
Process States A state of a process describes the activity that the process is doing at a certain moment in time. New : A newly created process, not in the ready queue. Ready : It can use the CPU , if available. Running : If it is currently in the CPU. Waiting : Waiting for some event ex: I/O Abend : Stops executing due to an error. End : Finished executing properly. Suspended: Stops temporarily while the OS uses the CPU
States of processes SUSPENDED END NEW READY RUNNING WAITING ABEND
Causes of state change When a process executes, it changes states and interrupts cause process to change states. Current State New state Interrupt Running End EOP ( End of Program) Running (Abnormal end) Running (Start I/O) ABEND Trap Blocked for I/O System Call (SIO)
Depiction of state change EOP END TRAP ABEND RUNNING SIO BLOCKED
Process Continued… n The activity of a process is controlled by a data structure called Process Control Block(PCB). n A PCB is created every time a program is loaded to be executed. n So, a process is defined by PCB-Program couple.
Structure of PCB contains information about processes, for instance: Ø the current state of a process ØUnique identification of process ØProcess priority ØContents of some CPU registers ØInstruction Pointer (IP), also known as PC ØBase and limit registers ØTime limits and I/O status information
Structure of PCB Contd… PROGRAM S T A C K Pointer to next PCB Process name or ID Base code Limit…. Code IP or PC Stack Pointer Registers State MODE Interrupt Flags. …. . Thread Control Block (TCB)
Process Continued… A thread is known as “the unit of execution” of a process and it is represented by the Thread Control Block (TCB). The TCB consists of four fields: PC, stack pointer, the contents of some registers, and the state.
Process Continued… We can now observe how each stage of a process takes place by the aid of a state diagrams. Process creation : n An OS can create one or more processes, via a create-process system call. n During the course of execution an user process may create new processes or threads as well. In this case, the creating process (thread) is called the parent and the created (new) process (thread) is named the child.
Process Creation New Create Ready The process is created and then inserted at the back of the ready queue, it moves to the head of the queue according to a scheduling policy.
Process Creation Contd… Program Load PCB OS code Create stack
Process Creation (closer view) Cont… Create PCB stack heap bss OS Load Program file header data code Process working space Memory symbol table Disk
Process working space (run-time environment) stack Dynamic link, return address, Local variables, function Parameters, … heap int z; bss int y = 7; data Dynamically allocated variables Global and static variables Constants / initialized data code Program text (write protected) malloc(n); x = 4; Process working space
Process working space (run-time environment) Process working space sum Local bss: means “block started by symbol” and has that name for historical reasons. stack Local void sub(float total, int part ) { int List[5]; float sum; … Local } Local Parameter heap Parameter int z; bss Dynamic Link int y = 7; data malloc(n); x = 4; code Return Address Activation record
Thread working space (run-time environment) Multithreading: Each thread is a unit of execution. stack-T 1 stack-T 2 stack-main Multithreaded processes need a stack per thread. All threads shared the same address space. Each thread has is own TCB. heap bss data code
Thread working space (run-time environment) Multithreading: All threads share the CPU-PC and CPU-SP. In this picture thread-T 2 is using the CPU. PCB stack-T 1 stack-T 2 CPU sp stack-main pc regs heap bss data code Process ID SP PC regs state TCB-T 1 SP PC regs state TCB-T 2 SP PC regs state TCB-main . . . Open files Other resources. . .
Memory snap shot of two processes in Ready State INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY LOADER RUNNING READY PCB 1 1 st a c k PCB 2 2 NULL st a c k The PCB is stored in the OS memory area in a linked list.
Ready to Running Dispatcher RUNNING READY Timer Interrupt When a process reaches the head of the queue and the CPU is available, the process is dispatched which means that the CPU is assigned to the process. This cause a transition from the ready state to the running state. When the time slice of the running process expires it goes back to the ready state.
Ready to Running INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY LOADER RUNNING READY PCB 1 1 st a c k PCB 2 2 st a c k INTERRUPT FLAGS IP OV MP PI Accumulator TI I/O SVC MASK TO BE DEFINED LATER Mode CPU
Ready to Running INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY LOADER RUNNING READY PCB 1 1 st a c k PCB 2 2 st a c k INTERRUPT FLAGS IP OV MP PI Accumulator TI I/O SVC PCB 2 2 st a c k MASK TO BE DEFINED LATER Mode CPU
Running to Ready LOADER INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY RUNNING READY PCB 2 PCB 1 1 st a c k INTERRUPT FLAGS IP OV MP PI Accumulator TI I/O SVC 2 st a c k MASK TO BE DEFINED LATER Mode CPU
Running to Ready INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY LOADER RUNNING READY PCB 2 2 st a c k 1 INTERRUPT FLAGS IP OV MP PCB 2 PCB 1 PI Accumulator TI I/O SVC 2 PCB 1 st a c k MASK TO BE DEFINED LATER Mode CPU
Process Continued… As the OS switches the allocation of CPU among processes it uses the PCB to store the CPU information or context, which represents the state of the process. In the previous example we have seen how the OS performed a context switch between processes P 2(from Running to Ready) and P 1(from Ready to Running). When a context switch occurs we need to save the state of the running process in its PCB and load the state of the new process in the CPU.
Case of Timer interrupt P 2 P 1 Dispatch RUNNING READY Timer Interrupt After a timer interrupt, the OS move P 1 back to the ready state and the CPU Is assigned to P 2.
Context switching EXECUTING P 1 OS Save state into PCB 1 WAITING P 2 WAITING TIMER WAITING Reload state from PCB 2 DISPATCH WAITING EXECUTING Save state into PCB 2 TIMER WAITING Reload state from PCB 1 EXECUTING DISPATCH WAITING
Case of I/O interrupt RUNNING READY Start I/O (System call) I/O Interrupt WAITING
Case of I/O interrupt Contd. . LOADER INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY RUNNING READY PCB 1 PCB 2 PCB 3 SIO I/O INTERRUPT FLAGS IP OV MP PI Accumulator TI I/O SVC MASK TO BE DEFINED LATER I/O DEVICE
Case of I/O interrupt Contd. . LOADER INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY RUNNING READY PCB 1 PCB 2 PCB 3 I/O INTERRUPT FLAGS IP PCB 2 OV MP PI Accumulator TI I/O SVC MASK TO BE DEFINED LATER I/O DEVICE
Case of I/O interrupt Contd. . LOADER INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY READY OS PCB 1 I/O PCB 2 PCB 3 SUSPEND INTERRUPT FLAGS IP OV MP PI Accumulator RUNNING TI I/O SVC MASK TO BE DEFINED LATER I/O DEVICE
Case of I/O interrupt Contd. . LOADER INTERRUPT HANDLER DISPATCHER RUNTIME LIBRARY READY OS PCB 1 I/O OV MP PI Accumulator PCB 2 PCB 3 SUSPEND INTERRUPT FLAGS IP PCB 3 RUNNING TI I/O SVC MASK TO BE DEFINED LATER I/O DEVICE
Context switching EXECUTING P 3 OS Save state into PCB 3 Put P 3 into the I/O queue WAITING IN I/O QUEUE WAITING Suspend P 2 READY STATE SIO WAITING EXECUTING Reload state from PCB 2 IN I/O STATE P 2 DISPATCH EXECUTING I/O INTERRUPT HANDLE I/O Put P 3 in Ready state Resume P 2 READY STATE SUSPENDED DISPATCH EXECUTING WAITING
n Handling I/O: Here the process waiting in the I/O queue is moved back to the ready state after the I/O request is completed.
End of Process END EOP RUNNING TRAP ABEND
PCB prog stack TRAP 1. ABORT PROGRAM 2. ERROR MESSAGE 3. FREE RESOURCES 4. DELETE PCB OS EOP 1. PROGRAM RUNS SUCCESSFULLY 2. FREE RESOURCES 3. DELETE PCB
- Multiprogramming operating system
- Ics and multiprogramming
- Operating system unit
- Multiprogramming with a fixed number of tasks
- Uniprogramming
- Nachos multiprogramming
- Alokasi memori pada sistem multiprogramming
- The multiprogramming system
- What is the objective of multiprogramming? *
- There is there are ejemplos
- There is there are part of speech
- There is there are negative form
- There is there are cümleler
- No, there aren’t.
- There is there are
- Mathematics john's favourite subject
- Here there over there
- Some any правило
- Sustantivos en ingles contables
- Pep unit
- There was there were ile ilgili cümleler
- Jeopardy countable and uncountable
- There is there are
- Arehay
- There's and there are
- If there is no struggle there is no progress examples
- Ideal self and real self example
- Pengertian marketing concept
- Myasthenia gravis concept map
- Discuss in detail the concept and process of hydrosere'
- Concept map of pollination
- It is a static entity made up of program statement
- Process concept
- Elements of communication
- Bones practical exam
- Procedural vs substantive due process
- Business process levels
- Ergodicty
- What is process to process delivery
- Coronoid and condylar process
- Minitab