Professional Documents
Culture Documents
Lesson 3:
Introduction to Process Management
Jesús Carretero Pérez
David Expósito Singh
José Daniel García Sánchez
Francisco Javier García Blas
Florin Isaila
Operating Systems 1
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 2
Process
Operating Systems 3
Program execution
Executable Process A1
Program
Main Memory
A
Process A2
Operating Systems 4
Memory representation
stack
• A process needs
memory for
instructions and data.
Operating Systems 5
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 6
Basic lifecycle of process
As many as
processors
Activation Running
Fin
Wait an event
Time-slice
finished
Ready Blocked
Operating Systems 7
Simplified queuing model:
Single processor
New processes Processor
Finished processes
End of time-slice
Ev 1
Ev 2
…
Ev 3
Operating Systems 8
Simplified queuing model:
Multiple processors
Finished
New processes Processor Processes
End of time-slice
Ev 1
Ev 2
Ev 3 Operating Systems 9
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 10
Process information
• Three categories:
– Information stored in the processor.
– Information stored in memory.
– Additional information managed by operating system.
Operating Systems 11
Processor state
¨Context switch:
¨ Save processor state for outgoing process.
¨ Restore processor state for incoming process.
Operating Systems 12
Memory image of a process
Operating Systems 13
Memory image models:
Single region
Operating Systems 14
Memory image models:
Multiple regions
data
text
15
Operating Systems
Memory image models:
Multiple regions
Operating Systems 16
Operating system information
Operating Systems 17
Contenidos del BCP
• Identification Example:
information. •Process identification.
Scheduling and state information:
•Process state. identification.
•Parent process
• Processor state. •Waited event (if blocked).
•User information.
•Process priority.
• Process control •Scheduling information.
information. Allocated regions description.
•Per region information.
Allocated resources:
•Open files.
On process
•Used start: ports.
communication
•Initial values for processor state.
•Timers.
After context
Pointers switch:process
for structuring
•Copy (or
queues state values to processor.
rings).
Information for inter process
communication.
Operating Systems 18
Information out of PCB
Operating Systems 19
Page Table
Operating Systems 20
File position pointers
Operating Systems 21
Example: Running a command
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char** argv) {
pid_t pid;
pid = fork();
switch (pid) {
case -1: /* error */
prog cat f1
exit(-1);
case 0: /* proceso hijo */
if (execvp(argv[1], &argv[1])<0) { perror(“error”); }
break;
default:
printf(“Proceso padre”);
}
return 0;
}
Operating Systems 22
Fork service
• pid_t fork(void);
• Returns:
– -1 on error.
– In parent process: child process descriptor.
– In child process: 0.
Operating Systems 23
Fork service
Process A
FORK
Process A’
Operating Systems 24
Exec service
• Description:
– Returns -1 on error, otherwise it does not return.
– The same process runs another program.
– Open files remain open.
– Signals with default action remain defaulted, signals with handler take default
action.
Operating Systems 25
Exec service
Process A
EXEC
Process A’
Proceso B
Operating Systems 26
Exit service
void exit(status);
Operating Systems 27
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 28
Operating system types
Operating Systems
Multiprocess Monoprocess
(several processes
running) (single process)
Operating Systems 29
Principles of multitasking
Operating Systems 30
Advantages of multitasking
Operating Systems 31
Multiprogramming degree
• Multiprogramming
degree: Number of 100%
active processes.
% CPU utilization
• Main memory needs:
System without virtual
memory.
Multiprogramming degree
Operating Systems 32
Multiprogramming: CPU use
Execution
1 process
I/O
2 processes
Operating Systems 33
Multiprogramming and virtual memory
Operating Systems 34
Memory needs:
Page frames per process
Virtual memory system
Multiprogramming degree
Operating Systems 35
Performance:
Small physical memory
¨When
multiprogramming
degree increases: 100%
¨ Resident set size
decreases for each
process.
% CPU utilization
¨Trashing happens before
achieving a high CPU
utilization percentage.
Operating Systems 36
Performance:
Large physical memory
• When multiprogramming
degree increases:
– Resident set size decreases for 100%
each process.
% CPU utilization
• High CPU utilization percentage
is achieved with less processes
that fit in memory.
Multiprogramming degree
Operating Systems 37
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 38
Context switching
• Actions:
– Save process state in PCB for process in execution.
– Restore state of new process in processor.
Operating Systems 39
Context switch
Operating Systems 40
Context switching types
Operating Systems 41
Contents
¨Process concept.
¨Basic lifecycle of a process.
¨Process information
¨Multitasking.
¨Context switch.
¨Generating an executable.
Operating Systems 42
Executable generation
a.c b.c
Compiler Compiler
Linker (ld)
Executable object file (contains code and data
p for all defined functions in a.c and b.c).
Operating Systems 43
Link Editor (linker)
n Relocates symbols:
n From relative positions in .o to absolute positions in
executable: adjust refs to these new positions.
n Symbols: refs to functions and data.
Operating Systems 44
Ejemplo: Formato ELF
Operating Systems 45
ELF format
Operating Systems 46
Executable load
DISK
0 MEMORY
ELF header
Virtual addr
Program header table Process image
(required for executables) 0x080483e0
init and shared lib
.text section segments
.data section
0x08048494
.text segment
.bss section
(r/o)
.symtab
.rel.text 0x0804a010
.data segment
.rel.data (initialized r/w)
.debug
0x0804a3b0
Section header table .bss segment
(required for relocatables) (uninitialized r/w)
Operating Systems 47
Static library
a.c b.c
Compiler Compiler
Static library: file with
a.o b.o libc.a contatenation of relocatable
object files.
Linker (ld)
Executable object file: includes code from functions
p in libc used in the program.
Operating Systems 48
Static and dynamic libraries
Operating Systems 49
Dynamic libraries
a.c b.c
Compiler Compiler
a.o b.o
Linker (ld)
Operating Systems 51
OPERATING SYSTEMS:
Lesson 3:
Introduction to Process Management
Jesús Carretero Pérez
David Expósito Singh
José Daniel García Sánchez
Francisco Javier García Blas
Florin Isaila
Operating Systems 52