Académique Documents
Professionnel Documents
Culture Documents
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Process (Definition)
A process not only a code but includes current activity
represented by:
program counter value (next instr. To run)
Content of processor registers
process stack (local variables and returning address in
case of a call for routines, etc.)
data section: (like global variables)
A possible heap (for memory dynamically allocated
during process time)
Process in memory
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
2/17/2016
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Process Creation
Four principal events that cause processes to be
created:
1. System initialization (next slide).
2. Execution of a process creation system call by
a running process.
3. A user request to create a new process.
4. Initiation of a batch job.
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
2/17/2016
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
2/17/2016
Process Termination
Typical conditions which terminate a process:
1. Normal exit
2. Error exit
3. Fatal error
4. Killed by another process
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
2/17/2016
2/17/2016
Modeling Multiprogramming
2/17/2016
Figure 2-12. The first column lists some items shared by all
threads in a process. The second one lists some items
private to each thread.
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
2/17/2016
Implementing Threads
in User Space
(a)
(b)
Managing Threads
Two main places to implement threads: user space and the kernel
(can be hybrid)
1- Put the threads package entirely in user space
The kernel manages ordinary, single-threaded processes.
Advantages:
A user-level threads package can be implemented on an
operating system that does not support threads
Allows each process to have its own customized scheduling
algorithm
With this approach, threads are implemented by a library. The
threads run on top of a run-time system, which is a collection of
procedures that manage threads.
2/17/2016
Synchronization
Concurrent access to shared data may result in data
inconsistency
Maintaining data consistency requires mechanisms
to ensure the orderly execution of cooperating
processes
Account r1
2000
2000
r2
1000
3000 1000
0
0
2000 0
500
1500 500
1500
3000
3000
Race Condition
Race condition is when the outcome depends on the
particular order in which instructions execute
To guard against race condition, use
SYNCHRONIZATION.
Synchronize processes/ threads
Synchronization is the coordination of the activities of 2
or more processes that usually need to execute the
following activities:
Compete for resources in mutually exclusive manner
(i.e., one at a time)
Cooperate in sequencing or ordering specific events in
their individual activities
2/17/2016
Another example:
P1 and P2 share a global variable x
P1: y local
.
x+=10;
y=x;
P2: y local
.
x++;
y+=x;
.
Critical sections CS
Solution to Critical-Section
Problem
1. Mutual Exclusion - If process Pi is executing in its critical section, then no
other processes can be executing in their critical sections
2. Progress - If no process is executing in its critical section and there exist
some processes that wish to enter their critical section, then the
selection of the processes that will enter the critical section next cannot
be postponed indefinitely absence of deadlock
3. Bounded Waiting - A bound must exist on the number of times that
other processes are allowed to enter their critical sections after a
process has made a request to enter its critical section and before that
request is granted absence of starvation
Assume that each process executes at a nonzero speed
BUT No assumption concerning relative speed of the n processes
10
2/17/2016
Entry
While( turn !=1);
CRITICAL SECTION
Exit
Turn=0;
Non critical section
---P1 -------------
11
2/17/2016
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
12
2/17/2016
Semaphore
Synchronization tool that does not require busy waiting
Semaphore S integer variable
Two standard operations modify S: acquire() and release()
Originally called P() and V()
Less complicated
Can only be accessed via two indivisible (atomic) operations
13