0% found this document useful (0 votes)
17 views8 pages

Lecture 2

Uploaded by

Surya Basnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

Lecture 2

Uploaded by

Surya Basnet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lecture 2: The Process

Abstraction
OS provides process abstraction
• When you run an exe file, the OS creates a
process = a running program
• OS timeshares CPU across multiple processes:
virtualizes CPU
• OS has a CPU scheduler that picks one of the
many active processes to execute on a CPU
– Policy: which process to run
– Mechanism: how to “context switch” between
processes
2
What constitutes a process?
• A unique identifier (PID)
• Memory image
– Code & data (static)
– Stack and heap (dynamic)
• CPU context: registers
– Program counter
– Current operands
– Stack pointer
• File descriptors
– Pointers to open files and
devices
3
How does OS create a process?
• Allocates memory
and creates memory
image
– Loads code, data
from disk exe
– Creates runtime
stack, heap
• Opens basic files
– STD IN, OUT,
ERR
• Initializes CPU
registers
– PC points to first
instruction

4
States of a process
• Running: currently executing on CPU
• Ready: waiting to be scheduled
• Blocked: suspended, not ready to run
– Why? Waiting for some event, e.g., process issues
a read from disk
– When is it unblocked? Disk issues an interrupt
when data is ready
• New: being created, yet to run
• Dead: terminated
5
Process State Transitions

6
Example: Process States

7
OS data structures
• OS maintains a data structure (e.g., list) of all
active processes
• Information about each process is stored in a
process control block (PCB)
– Process identifier
– Process state
– Pointers to other related processes (parent)
– CPU context of the process (saved when the process
is suspended)
– Pointers to memory locations
– Pointers to open files

You might also like