Chapter 2: Process management
1. Introduction
2. Main concepts
3. Processes implementation
4. Threads
5. CPU Scheduling
References
• Silberschatz Galvin. Operating System Concepts 7th
edition
• Operating Systems - William Stalling 6th edition
• Libro de problemas de SO (DTIC)
Introduction
• Concurrent Processing:
• Multiprogramming
• Multiprocessing
• Distributed Processing
• Process: running program
• Process ≠ program
• OS Services
• Concurrent running
• Processes synchronization
• Communication among processes
Main concepts (I)
Relation among processes:
• Independent
• Cooperative
• Competitive
State of a process:
• Release
• Admit
Loading…
• Running
• Ready
• Blocked
Running
Admit
Ready
Blocked
Overall system state
Main concepts (II)
Operations on processes:
• Creating processes: fork
• Parent-child process
• Processes tree
• Finishing processes: exit, kill
root
pagedaemon
Loading…
swapper init
usuario1 usuario2 usuario3
CAD BD
SQL1 SQL2 Impresión
Process Tree on a UNIX system representative
Processes implementation (I)
The process control block (PCB) is the data
structure of the system that keeps all
information about a process.
The PCB of each process is created when a
process is created and destroyed when the
process ends.
The information of PCB includes>
Process identifier: pid
State of a process
CPU registers: CP, flags, ...
Information regarding CPU scheduling:
priority,...
Memory management information, pointers,
tables, registers, ...
Timing information: time spent, time limits, ...
I/O State Information: I/O list of devices, open
files list, ...
Processes implementation (II)
pid
estado
registros
prioridad
punteros a memoria
lista de
archivos abiertos
lista de
dispositivos de E/S
asignados
PCB de un proceso
Processes implementation (III)
Changing context of a process
It is to remove from the CPU a running process
and to assign the CPU to a ready state process
It is called also execution context of the program
• Actions needed
• To save the contents of the running
process to its PCB
• Restore the context of the new process
from its PCB
• They reduce the CPU usage
t t t
P1 P2 P1 P3
T(P1) + T(P2) + T(P3)
Usage =
T(P1) + T(P2) + T(P3) + 3·t
Processes implementation (IV)
Changing context of a process
• Reasons that cause it:
• Normal completion of a running process
• Waiting for a process to perform an I/O
operation
• Existence of an interruption
OS as interrupt handlers
excepción del llamada al
reloj periféricos
procesador sistema
Guardar el contexto del proceso en ejecución
Anotar Pasar a
Pasar a Resolver
el avance espera
preparado la llamada
del tiempo Finalizar el proceso
el proceso que al sistema
el proceso seleccionado
Si tiempo límite esperaba
en ejecución
excedido: la finalización
proceso de la E/S Crear hijo:
en ejecución a preparado
a preparado
Planificador: Selección del próximo proceso
Restaurar el contexto del proceso seleccionado
Processes implementation (V)
Queues of processes: abstract data type that
holds the PCB processes in a dynamic list
• It maintains a queue of processes for each
state in the process
Loading…
Threads
Independent control flows within a single
process with its own stack, local variables
and CP.
Advantages
Sharing links and resources address space
The time spent in context switching /
changing is less than the complete process
Disadvantages
Synchronization between threads
and between processes.
Complexity in programming and
debugging
Design programs based on thread
• Potential parallelism applications
• Existence of many tasks I / S
• Existence of asynchronous events
CPU Scheduling (I)
Scheduling concepts
Lack of resources
Exclusive access resources: CPU,
Printers, etc.
Allocation Policy
Scheduling situations
When a process changes from running to
blocked state
When a process changes from running to
ready state
When a process changes from blocked to
ready state
When a process terminates
Scheduling types
Preemptive
Nonpreemptive
CPU Scheduling (II)
Scheduling for the CPU: Scheduler
Loader: Dispatcher
Changing context
It jumps to the process proper point to
continue from there
Scheduling criteria
tCPU_ocupa
Use = da
CPU use tCPU_tot
al
nº procesos terminados
Performance Performance =
t
Turnaround time
Waiting time
Response time
CPU Scheduling (II)
Nonpreemptive scheduling algorithms
• First-Come, First-Served (FCFS)
• Priority scheduling
• Static
• Dynamic
• Shortest-Job-First (SJF)
CPU Scheduling (III)
Preemptive scheduling algorithms
• Round-Robin Scheduling (RR)
• Priority scheduling
• Shortest-Remainder-Time (SRT)
• Multilevel Queue Scheduling (MLQ)
• Number of queues
• Scheduling algorithm for each queue
• Queues priority
• Criteria indicating the queue where it enters a
task when it is needed
• Multilevel Feedback-Queue Scheduling
(MLFQ)
• Criteria that determine the movement of tasks
among queues
• Multiple-Processor Scheduling
• Real time Scheduling
CPU Scheduling (IV)
Evaluating the algorithms
• Criteria
• Maximize the use
• Maximize the performance
• Others or combination of both
• Deterministic Model
• Queue Model
• Simulation
• Implementation