Advanced Operating System
Advanced Operating System
Advanced OS
Chapter 2
Objectives
Expectations of a Process
Distributed Operating system
Virtualization of CPU
Virtualization of Memory
Expectations of a Process
Running a program does the following things:
fetches an instruction from memory,
decodes it (figuring out which instruction this is),
and executes it (i.e., it does the thing that it is supposed to do, like
multiply numbers together, memory access, conditional check,
jump to a function, allow access to other devices and so on).
After it is done with this instruction, the processor moves on to
the next instruction, and so on, and so on, until the program
finally completes1
Operating System
Will learn that while a program executes, a lot of other wild things are
going on with the primary goal of making the system easy to use.
Operating system (OS) software makes it easy to run program and programs at
the same
Virtualization of CPU
First program in Figure 2.1.
It calls a function called spin() that repeatedly checks the
time and returns once it has run for a second
Then, it prints out the string that the user passed in on the
command line, and repeats, forever.
Lets say we save this file as cpu.c and decide to compile
and run it on a system with a single processor (or CPU as
we will sometimes call it). Here is what we will see:
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <assert.h>
#include "common.h"
int
if (argc != 2) {
fprintf(stderr, "usage: cpu <string>\n");
exit(1);
while (1) {
Spin(1);
printf("%s\n", str);
return 0;
Virtualization of Memory
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
int
main(int argc, char *argv[])
{
int *p = malloc(sizeof(int));
assert(p != NULL);
printf("(%d) memory address of p: %08x\n",
getpid(), (unsigned) p);
*p = 0;
while (1) {
Spin(1);
*p = *p + 1;
printf("(%d) p: %d\n", getpid(), *p);
}
return 0;
}
// a1
// a2
// a3
// a4
Single Program
Line a1 shows allocation of some memory
Line a2 prints out the address of the memory
Line a3 puts the number zero into the first slot of the newly
allocated memory
Line a4 it loops, delaying for a second and incrementing the value
stored at the address held in p.
With every print statement, it also prints out what is called the
process identifier (the PID) of the running program.
PID is unique per running process.
Output of Program
prompt> ./mem
(2134) memory address of p: 00200000
(2134) p: 1
(2134) p: 2
(2134) p: 3
(2134) p: 4
(2134) p: 5
C
Multiple times
Each running program has allocated memory at the same
address (00200000),
Each seems to be updating the value at 00200000
independently
It is as if each running program has its own private
memory, instead of sharing the same physical memory
with other running programs
Each process accesses its own private virtual address
space
OS is virtualizing memory