0
0
Operating Systemsknowledge~30 mins

Process states (new, ready, running, waiting, terminated) in Operating Systems - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Process States in Operating Systems
📖 Scenario: Imagine you are learning how a computer manages tasks. Each task is called a process. Processes move through different states as the computer works on them.We will create a simple program that shows these process states and how a process moves from one state to another.
🎯 Goal: You will build a small program that defines the five main process states: new, ready, running, waiting, and terminated. Then, you will simulate moving a process through these states step-by-step.
📋 What You'll Learn
Create a dictionary called process_states with keys as state names and values as descriptions.
Create a variable called current_state to hold the process's current state.
Write a function called move_to_next_state that changes the current_state to the next logical state.
Add a final step to simulate the process moving through all states in order.
💡 Why This Matters
🌍 Real World
Understanding process states helps in knowing how computers manage multiple tasks efficiently and how operating systems schedule and control processes.
💼 Career
This knowledge is essential for roles in software development, system administration, and IT support where managing or optimizing system performance is important.
Progress0 / 4 steps
1
Create the process states dictionary
Create a dictionary called process_states with these exact entries: 'new' mapped to 'Process is being created', 'ready' mapped to 'Process is ready to run', 'running' mapped to 'Process is executing', 'waiting' mapped to 'Process is waiting for an event', and 'terminated' mapped to 'Process has finished execution'.
Operating Systems
Need a hint?

Use curly braces {} to create the dictionary and separate each key-value pair with a comma.

2
Set the initial current state
Create a variable called current_state and set it to the string 'new' to represent the process starting in the new state.
Operating Systems
Need a hint?

Assign the string 'new' to the variable current_state.

3
Write the function to move to the next state
Write a function called move_to_next_state that takes no arguments and changes the global variable current_state to the next state in this order: newreadyrunningwaitingterminated. Use an if-elif structure to check current_state and update it accordingly.
Operating Systems
Need a hint?

Remember to declare current_state as global inside the function to modify it.

Use if and elif to check the current state and update it step-by-step.

4
Simulate the process moving through all states
Write code that calls the move_to_next_state function four times to move the process from new to terminated. After each call, add a comment showing the current state variable name current_state to indicate the process's state at that point.
Operating Systems
Need a hint?

Call the function move_to_next_state() four times. After each call, add a comment showing the updated current_state.