OS Crashcourse
OS Crashcourse
OS Crashcourse
monitor user
set user mode
– command-line interpreter
– shell (in UNIX)
P1 P2 P3
0 24 27 30
0 3 6 30
0 3 7 8 12 16
0 2 4 5 7 11 16
n1 tn 1 n .
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
• Responsiveness
• Resource Sharing
• Economy
• Utilization of MP Architectures
• Shared data
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
int counter = 0;
item nextProduced;
while (1) {
while (counter == BUFFER_SIZE)
; /* do nothing */
buffer[in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
counter++;
}
item nextConsumed;
while (1) {
while (counter == 0)
; /* do nothing */
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
counter--;
}
counter++;
counter--;
register1 = counter
register1 = register1 + 1
counter = register1
register2 = counter
register2 = register2 – 1
counter = register2
return rv;
}
• Process Pi
do {
while (TestAndSet(lock)) ;
critical section
lock = false;
remainder section
}
Operating System Concepts
Semaphores
• Synchronization tool that does not require busy waiting.
• Semaphore S – integer variable
• can only be accessed via two indivisible (atomic)
operations
wait (S):
while S 0 do no-op;
S--;
signal (S):
S++;
• Shared data:
semaphore mutex; //initially mutex = 1
• Process Pi:
do {
wait(mutex);
critical section
signal(mutex);
remainder section
} while (1);
signal(S):
S.value++;
if (S.value <= 0) {
remove a process P from S.L;
wakeup(P);
}
• Shared data
semaphore chopstick[5];
Initially all values are 1
void putdown(int i) {
state[i] = thinking;
// test left and right neighbors
test((i+4) % 5);
test((i+1) % 5);
}
• Single-partition allocation
– Relocation-register scheme used to protect user processes from
each other, and from changing operating-system code and data.
– Relocation register contains value of smallest physical address;
limit register contains range of logical addresses – each logical
address must be less than the limit register.
OS OS OS OS
process 8 process 10
• Access Methods
• Directory Structure
• File Sharing
• Protection
Directory
Files
F1 F2 F4
F3
Fn
Naming problem
Grouping problem
•Path name
•Can have the same file name for different user
•Efficient searching
•No grouping capability
outer-index