Lesson 5 - State Transition of Process.pptx
Document Details
Uploaded by PatriRetinalite2478
Bulacan Agricultural State College
Full Transcript
STATE TRANSITION OF PROCESS A P R O C E S S I S A P R O G RA M I N E X E C U T I O N. I T ' S M O R E T H A N J U S T T H E P R O G RA M ' S C O D E , I T I N C LU D E S T H E P R O G RA M C O U N T E R ( I N D I C AT I N G T H E N E XT INSTRUCTION TO EXECUTE), THE CPU...
STATE TRANSITION OF PROCESS A P R O C E S S I S A P R O G RA M I N E X E C U T I O N. I T ' S M O R E T H A N J U S T T H E P R O G RA M ' S C O D E , I T I N C LU D E S T H E P R O G RA M C O U N T E R ( I N D I C AT I N G T H E N E XT INSTRUCTION TO EXECUTE), THE CPU R E G I S T E R S , M E M O RY , A N D O T H E R R E S O U RC E S A L LO C AT E D BY T H E O P E RAT I N G S Y S T E M. DIFFERENCE BETWEEN A PROGRAM AND A PROCESS Program: A passive entity, like a text file with instructions. It resides on disk and waits to be executed. Process: An active entity. It's the program in execution, along with all the associated resources. Example: The Microsoft Word file on your hard drive is a program. However, when you launch Word, it becomes a process as it starts executing on the CPU, managing memory, and performing tasks like formatting text PROCESS STATES A process can transition between several states during its lifetime. These states are: New: The process is being created. Example: When you double-click to open a PDF document, the operating system creates a new process for the PDF reader application (such as Adobe Acrobat). At this point, the process is in the new state. Ready: The process is loaded in memory and ready to execute but waiting for CPU time. Example: After the PDF reader is loaded into memory, it waits for the CPU to start executing its instructions. The process is in the ready state, waiting for the operating system's scheduler to give it CPU time. PROCESS STATES Running: The process is currently being executed by the CPU. Example: When the scheduler assigns CPU time to the PDF reader, it moves to the running state. Now, the process is actively running on the CPU, displaying the PDF file on your screen. Waiting: The process is waiting for some event to complete (e.g., I/O operation). Example: While you're viewing a PDF file, you may choose to print it. The print command may require waiting for the printer to be ready. In this case, the PDF reader process moves to the waiting state until the printer is available. Terminated: The process has finished executing and is removed from memory. Example: After you close the PDF reader, the process finishes its execution, releases all resources (like memory and file handles), and moves to the terminated state. PROCESS STATES PROCESS STATES New → Ready: When a process is created (e.g., opening a word document), it goes into the new state, and after being loaded into memory, it moves to the ready state. Ready → Running: The operating system's scheduler assigns CPU time to the process, making it running. For instance, if you're typing in the document, the process will move to the running state to perform that action. Running → Waiting: If the process needs to perform an I/O operation (e.g., waiting for data from the hard drive), it moves to the waiting state until the operation completes. Waiting → Ready: Once the I/O operation completes, the process moves back to the ready state, waiting for the CPU to execute the next instruction. Running → Ready: If the CPU's time slice for the process expires, it can be interrupted and moved back to the ready state, allowing another process to execute. Running → Terminated: When the process finishes executing (e.g., you close the document), it releases its resources and moves to the terminated state. PROCESS STATES The Process Control Block (PCB) is a data structure maintained by the operating system to keep track of important information related to a process. It includes details like: Process state (new, ready, running, waiting, or terminated) Program counter (address of the next instruction) CPU registers (current values of registers) Memory management information (memory allocated to the process) I/O status (open files, I/O devices being used) Example: When you open a web browser, the operating system creates a PCB for the browser process. The PCB tracks the state of the process, such as whether it's running or waiting for data from the network (e.g., loading a webpage). The operating system constantly updates the PCB as the browser's state changes. PROCESS STATES DIAGRAM Process Control Block (PCB): Web Browser (Google Chrome) Process State: Ready → Running → Waiting → Running → Terminated Program Counter: Points to the next instruction for rendering the webpage. CPU Registers: Stores values related to the browser's session (e.g., cookies). Memory Management: Memory allocated for tabs, history, and cache. I/O Devices: Using the network for loading web pages. EXAMPLE OF STATE TRANSITIONS IN REAL LIFE Imagine you're printing a document from Microsoft Word: You open Word and start typing: The Word process is created (New) and moves to Ready, waiting for CPU time. You hit "Print": The process starts using the CPU to send data to the printer (Running). While waiting for the printer to respond, the process may go into a Waiting state. Once the printer is ready, the process resumes (Ready → Running) and completes the print job. After you're done and close the document, Word moves to the Terminated state, releasing its resources. THANK YOU Audi Alteram Partem Prof Juls