Professional Documents
Culture Documents
Giuseppe Anastasi
g.anastasi@iet.unipi.it
Pervasive Computing & Networking Lab. (PerLab)
Dept. of Information Engineering, University of Pisa
PerLab
Overview
PerLab
Processes
Threads
CPU Scheduling
Overview
PerLab
Processes
Threads
CPU Scheduling
A process includes
Code section
Current activity
Current activity is defined by
Program Counter (IP Register)
CPU Registers
Stack
Data Section (global variables)
…
Process Creation
PerLab
Resource sharing
Parent and children share all resources.
Children share subset of parent’s resources.
Parent and child share no resources.
Execution
Parent and children execute concurrently.
Parent waits until children terminate.
Processes & Threads 8 Operating Systems
Address space
Child duplicate of parent.
Child has a program loaded into it.
UNIX examples
Each process is identified by the process identifier
fork system call creates new process
exec system call used after a fork to replace the
process’ memory space with a new program.
# include <iostream.h>
void main(int argc, char* argv[]) {
int pid;
pid=fork(); /* genera un nuovo processo */
if(pid<0) { /* errore */
cout << “Errore nella creazione del processo” << "\n\n”;
exit(-1);
}
else if(pid==0) { /* processo figlio */
execlp(“/bin/ls”, “ls”, NULL);
}
else { /* processo genitore */
wait(NULL);
cout << “Il processo figlio ha terminato” << "\n\n”;
exit(0);
}
}
Processes & Threads 10 Operating Systems
Process Termination
PerLab
Context Switch
PerLab
CPU Scheduler
PerLab
Processes
Threads
CPU Scheduling
Process
PerLab
Resource ownership
A process is an entity with some allocated resources
Main memory
I/O devices
Files
…..
Scheduling/execution
A process can be viewed as a sequence of states
(execution path)
The execution path of a process may be interleaved
with the execution paths of other process
The process is the entity than can be scheduled for
execution
Processes & Threads 17 Operating Systems
Benefits
PerLab
Responsiveness
An interactive application can continue its execution even if a part
of it is blocked or is doing a very long operation
Resource Sharing
Thread performing different activity within the same application
can share resources
Economy
Thread creation management is much easier than process
creation and management
User Threads
PerLab
Examples
Windows XP/2000
Mac OS X
Linux
Solaris
Tru64 UNIX (Digital UNIX)
Multithreading Models
PerLab
Many-to-One
One-to-One
Many-to-Many
Many-to-One
PerLab
One-to-One
PerLab
One-to-one Model
PerLab
Many-to-Many Model
PerLab
Two-level Model
PerLab
Examples
IRIX
HP-UX
Tru64 UNIX
Solaris 8 and earlier
Thread Libraries
PerLab
Pthreads
PerLab
Windows XP Threads
Linux Thread
Windows XP Threads
PerLab
Linux Threads
PerLab
Linux Threads
PerLab
Processes
Threads
CPU Scheduling
CPU Scheduler
PerLab
Dispatcher
PerLab
Dispatch latency
time it takes for the dispatcher to stop one process and
start another running.
should be minimized
Processes & Threads 45 Operating Systems
Type of scheduling
PerLab
Batch Systems
Maximize the resource utilization
Interactive Systems
Minimize response times
Real-Time Systems
Meet Temporal Constraints
Objectives
PerLab
General
Fairness
Load Balancing (multi-processor systems)
Batch Systems
CPU utilization (% of time the CPU is executing processes)
Throughput (# of processes executed per time unit)
Turnaround time (amount of time to execute a particular process)
Interactive Systems
Response time
amount of time it takes from when a request was submitted until the first
response is produced, not output
Real-Time Systems
Temporal Constraints
Scheduling Algorithms
PerLab
Batch Systems
First-Come First-Served (FCFS)
Shortest Job First (SJF), Shortest Remaining Job First
(SRJF)
Approximated SJF
Interactive Systems
Round Robin (RR)
Priority-based
Soft Real-Time Systems
Priority-based?
Processes & Threads 48 Operating Systems
General-purpose systems
PerLab
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS.
When it gains CPU, job receives 8 milliseconds. If it
does not finish in 8 milliseconds, job is moved to
queue Q1.
At Q1 job is again served FCFS and receives 16
additional milliseconds. If it still does not complete, it
is preempted and moved to queue Q2.
Processes & Threads 53 Operating Systems
Windows XP scheduling
Linux scheduling
Windows XP Scheduling
PerLab
Kernel Priorities
PerLab
Priority classes
REALTIME_PRIORITY_CLASS Real-time Class
HIGH_PRIORITY_CLASS Variable Class
ABOVE_NORMAL_PRIORITY_CLASS Variable Class
NORMAL_PRIORITY_CLASS Variable Class
BELOW_NORMAL_PRIORITY_CLASS Variable Class
IDLE_PRIORITY_CLASS Variable Class
Relative Priority
TIME_CRITICAL
HIGHEST
ABOVE_NORMAL
NORMAL
BELOW_NORMAL
LOWEST
IDLE
Windows XP Priorities
PerLab
Background/Foreground processes
The time slice of the foreground process is increased
(typically by a factor 3)
RunQueue
PerLab
Questions?
PerLab