Consider a program that is loaded into memory and executed by the CPU. Which sequence correctly shows the typical states a process goes through from start to finish?
Think about the order: a process is created, waits to run, runs, may wait for input/output, then finishes.
The typical process lifecycle starts with creation (New), then moves to Ready state waiting for CPU time, then Running when executing. If it needs to wait for input/output, it goes to Waiting, and finally ends in Terminated.
What is the main job of the process scheduler in an operating system?
Think about how the CPU chooses which program to run when multiple are ready.
The process scheduler manages CPU time by selecting which process to run next, ensuring fair and efficient use of the CPU.
Which of the following statements correctly distinguishes a process from a thread?
Consider how memory is allocated and shared between processes and threads.
Processes have separate memory spaces, so they do not share data directly. Threads run inside a process and share the same memory, allowing faster communication but requiring careful synchronization.
What causes a process to become a zombie in an operating system?
Think about what happens after a process ends but before the system cleans it up.
A zombie process is one that has completed execution but still has an entry in the process table because its parent process has not yet collected its exit status.
Given the following Python code snippet that uses the os module to create a child process, what will be printed?
import os
pid = os.fork()
if pid == 0:
print(f"Child process: {os.getpid()}")
else:
print(f"Parent process: {os.getpid()}, child PID: {pid}")import os pid = os.fork() if pid == 0: print(f"Child process: {os.getpid()}") else: print(f"Parent process: {os.getpid()}, child PID: {pid}")
Remember that os.fork() creates a new process that runs the same code after the fork.
The os.fork() call creates a child process. The child process gets 0 as the return value, so it prints its own PID. The parent gets the child's PID and prints both its own PID and the child's PID. Thus, two lines are printed.