OS processes and threads notes
OS processes and threads notes
Chapter 2
Processes and threads
Processes
Threads
Scheduling
Interprocess communication
Classical IPC problems
D
C
B
A
Time
CS 1550, cs.pitt.edu (origin 4
aly modified by Ethan L. Mil Chapter 2
When is a process created?
Processes can be created in two ways
System initialization: one or more processes created when
the OS starts up
Execution of a process creation system call: something
explicitly asks for a new process
System calls can come from
User request to create a new process (system call executed
from user shell)
Already running processes
User programs
System daemons
0 1 … N-2 N-1
Scheduler
CS 1550, cs.pitt.edu (origin 9
aly modified by Ethan L. Mil Chapter 2
What’s in a process table entry?
Process management File management
May be Registers Root directory
stored Program counter Working (current) directory
on stack CPU status word File descriptors
Stack pointer User ID
Process state Group ID
Priority / scheduling parameters
Process ID
Parent process ID
Memory management
Signals
Pointers to text, data, stack
Process start time
or
Total CPU usage
Pointer to page table
User
space
Threads Threads
System Kernel Kernel
space
CS 1550, cs.pitt.edu (origin 12
aly modified by Ethan L. Mil Chapter 2
Process & thread information
User space
Process
Thread 1’s
stack
Thread 3’s
stack
Thread 2’s
stack
Kernel
Less waiting
Threads are faster to create
or destroy
No separate address space
Overlap computation and
I/O
Could be done without
threads, but it’s harder
Kernel
Example: word processor
Thread to read from keyboard
Thread to format document
Thread to write to disk
CS 1550, cs.pitt.edu (origin 15
aly modified by Ethan L. Mil Chapter 2
Multithreaded Web server
Dispatcher while(TRUE) {
thread getNextRequest(&buf);
Worker handoffWork(&buf);
thread }
while(TRUE) {
waitForWork(&buf);
lookForPageInCache(&buf,&page);
if(pageNotInCache(&page)) {
Kernel
readPageFromDisk(&buf,&page);
Web page }
cache returnPage(&page);
Network
connection }
Thread
Kernel Kernel
I/O bound
Total CPU usage
Time
CS 1550, cs.pitt.edu (origin 20
aly modified by Ethan L. Mil Chapter 2
When are processes scheduled?
At the time they enter the system
Common in batch systems
Two types of batch scheduling
Submission of a new job causes the scheduler to run
Scheduling only done when a job voluntarily gives up the CPU
(i.e., while waiting for an I/O request)
At relatively fixed intervals (clock interrupts)
Necessary for interactive systems
May also be used for batch systems
Scheduling algorithms at each interrupt, and picks the next
process from the pool of “ready” processes
A B C D