1.6 Operating Systems / Processes 1.6 Operating Systems ...
1.6 Operating Systems / Processes 1.6 Operating Systems ...
1.6 Operating Systems / Processes 1.6 Operating Systems ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.1 Definition of the Term Process [Task]<br />
WS 05/06<br />
Execution of a Program controlled by the operating system.<br />
(Hint: one program can be started many times. On each start an new process is created)<br />
– The operating system creates a virtual Computer for each<br />
program it runs. i.e. Before execution of program instructions the MMU setup<br />
is changed to restrict the memory access to the parts of the RAM which belong to the<br />
program.<br />
● The program addresses are mapped to the real memory adresses by<br />
a table and calculations in the MMU. The program addresses are<br />
also called virtual addresses because they refer to a virtual<br />
computer.<br />
● The set of all virtual addresses is called process address space or<br />
virtual address space.<br />
Inf3 25<br />
<strong>1.6</strong>.2<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
stack<br />
heap<br />
Uninitialized Data<br />
initialialized read write<br />
initialialized read only<br />
Text Segment<br />
(program instructions)<br />
Datensegment<br />
(Programmdata)<br />
Kernel data<br />
Kernel Kontext<br />
(data to contol the execution<br />
used by the operating system<br />
This part is read from<br />
the program file on<br />
hard disk<br />
WS 05/06<br />
Inf3 26<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.3<br />
#include <br />
integer k = 7;<br />
integer a[1000];<br />
char * fmt = "Pleas enter n";<br />
int factorial( int n ) { stack: Memory for<br />
int e,i;<br />
functions calls<br />
e = 1;<br />
for (i=2; i
Process A<br />
stack<br />
heap<br />
uninitialized<br />
Data<br />
initialized<br />
read write<br />
initialized<br />
read only<br />
Text Segment<br />
(Programmcode)<br />
Create process:<br />
fork();<br />
Start<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
stack B<br />
stack A 1<br />
heap A<br />
stack A 2<br />
heap B<br />
uninitialized<br />
Data A<br />
uninitialized<br />
Data B<br />
initialized A<br />
read write<br />
initialized B<br />
read write<br />
initialized<br />
read only<br />
Text Segment<br />
(Programmcode)<br />
Main memory<br />
Process B<br />
stack<br />
heap<br />
uninitialized<br />
Data<br />
initialized<br />
read write<br />
initialized<br />
read only<br />
Text Segment<br />
(Programmcode)<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.4 Attributes of a Process (continued)<br />
WS 05/06<br />
Hint: The memory<br />
mapping some time after<br />
the new process started<br />
is displayed here.<br />
Inf3 29<br />
– Status: sleeping (waiting), running, Kernel-Call (<strong>Operating</strong> system<br />
function call), trace (Debug),<br />
Prozess terminated (Runtime information is still needed): <br />
Assign CPU<br />
running<br />
Revoke assignment of CPU<br />
Wait for an<br />
event<br />
WS 05/06<br />
End<br />
(Termination)<br />
<strong>1.6</strong>.4 Attributes of a Process<br />
Values to characterize a process<br />
● Porcess ID (pid) unique number (short integer), is assigned to each<br />
process by the operating system (kernel)<br />
(query in a C program: function call: getpid())<br />
●<br />
●<br />
●<br />
●<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
Parent Process ID (Number of the process which generated this process.<br />
Function (system) calls: fork(), getppid().)<br />
User ID (Number to identify a user)<br />
– Real (uid, short integer) getuid()<br />
– Effektiv (valid for file access) (euid, short integer) geteuid()<br />
Group ID (Number to identify a group of users)<br />
– Real (gid, short integer) getgid()<br />
– Effective (valid for file access) (egid, short integer) getegid()<br />
Priority (nice value) (Attribute controls runtime assignment to processes)<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.4 Attributes of a Process (continued)<br />
– Working Directory (see exercises)<br />
– Table of Resources (for example: all data to access open files on hard disk)<br />
WS 05/06<br />
– Process-Group ID (on process can become the leader of a set of processes. This set<br />
is called the process group. With some system calls all processes of a process group can be<br />
adressed)<br />
– Terminal-Group ID (/dev/tty) (group of processes using the same<br />
input/output channel, for example the same PuTTY window)<br />
Inf3 30<br />
WS 05/06<br />
– Environment Variables (pair of stings: one string is used as index to store a string<br />
value: to set the language use LANG=EN, the first string LANG is the index, value is EN )<br />
ready<br />
Event occurred<br />
waiting<br />
– Umask (set permissions for the creation of new files)<br />
– User Limits (ulimit) (set limits for process: execution time, memory,<br />
files (number, size), number of (sub)processes created, ...)<br />
Inf3 31<br />
Inf3 32
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.5 Signals<br />
– Can be received by a process (and handled or ignored. This is controlled by<br />
the operating system and is distinct from events/interrupts received by the CPU from<br />
electronic devices)<br />
– Sources (for example: all data to access open files on hard disk)<br />
●<br />
●<br />
WS 05/06<br />
Hardware (if the CPU receives an interrupt while executing instructions of a user<br />
program due to some program error the execution is interrupted and the interrupt handler<br />
program part of the operating systems is run. As a result the process can receive a signal)<br />
– Divide by zero (Source: Floating point unit; Signal: Floating Point<br />
Exception SIGFPE)<br />
– Illegal memory access (Source: MMU; wrong address i.e. Not assigned to<br />
the process, attempt to write to a protected region; Signal: Segment<br />
Violation SIGSEG)<br />
– ...<br />
<strong>Operating</strong> System (Timer to wake up a process: SIGALRM,<br />
user enters +C: SIGINT, ...)<br />
● Other processes (System call kill(pid, signal), signals: SIGKILL, SIGTERM, SIGUSR1, SIGUSR2, ...)<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.6 Critical Regions (German: Kritische Abschnitte)<br />
– Lock Variable (Stores the value of the signal)<br />
– Test and Set must be performed in one interruptible (atomic)<br />
operation<br />
– Picture p. 92, [1] (C. Vogt: Betriebssysteme, Spektrum<br />
Akademischer Verlag, Heidelberg Berlin, 2001)<br />
Stop if signal<br />
is red<br />
Stop if signal<br />
is red<br />
Change<br />
signal to red<br />
Change<br />
signal to red<br />
critical<br />
region<br />
Change signal<br />
to green<br />
Change signal<br />
to green<br />
WS 05/06<br />
– Handler (is started when the signal is received, system call to install the handler:<br />
signal(signal, handler); Definition handler: void handleSig(int sig_no){ ... }<br />
Inf3 33<br />
Inf3 34<br />
<strong>1.6</strong>.6 Critical Regions (continued)<br />
– Semaphore (Generalization of Lock Variable) (Stores the value of<br />
the signal)<br />
Possible Operations:<br />
●<br />
●<br />
●<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
Initialize S(set a start value for example to the number of available resources)<br />
Pass (request one resource, if not available wait until the resource becomes available)<br />
Release (the resource)<br />
WS 05/06<br />
<strong>1.6</strong> <strong>Operating</strong> <strong>Systems</strong> / <strong>Processes</strong><br />
<strong>1.6</strong>.7 Dead Locks (German: Verklemmungen)<br />
– Example: Traffic jam<br />
Prerequisite for a Resource:<br />
●<br />
●<br />
●<br />
Exclusive usage<br />
Cannot be withdrawn<br />
1 < n Resources<br />
WS 05/06<br />
Picture p. 105, [1] (C. Vogt: Betriebssysteme, Spektrum<br />
Akademischer Verlag, Heidelberg Berlin, 2001)<br />
Inf3 35<br />
Inf3 36