Intro to Os 1 Virtualization Introduction Intro to Operating Systems
Intro to Os 1 Virtualization Introduction Intro to Operating Systems
After one instruction, the processor moves on to the next, and so on, until
the program is finished.
Virtualization
For the most part, the OS performs this via virtualization. This means that
the OS transforms a physical resource (such a processor, memory, or disk)
into a more general, powerful, and user-friendly virtual form. Because of
this, the operating system is sometimes called a Virtual Machine.
The OS also provides various interfaces (APIs) that you can call in order to
tell it what to do (like launch a program, allocate memory, or access a file).
Checks the time repeatedly and returns once it has run for 5 seconds.
Prints out the string the user passed on the command line
Repeats forever
Copy and paste the code below into the terminal to compile and run this
program as if it were running on a single-processor system. Our program
will pass in the string “A” as input.
A
A
A
A
A
...
This program will run forever, so type ^+C (control + C) to terminate the
program.
This time, let’s run several instances of the same program, cpu.c.
Even though we only have one CPU, all four programs seem to be operating
simultaneously! How does it work?
With help from the hardware, the operating system creates the illusion of
having a bunch of virtual CPUs.
We’ll use the pkill command to terminate all instances of the cpu program.
pkill cpu
The ability to run multiple applications at the same time presents new
challenges, like which of the two programs should execute first?
With all this considered, the operating system is, essentially, a resource
manager.
Memory Virtualization
Memory is a byte array. To read memory, you have to supply an address; to
write memory, and you have to specify the data to be written to the given
address.
Let’s look at the program to the left that uses malloc() to allocate memory
(). Compile and run program mem.c using the commands below.
Each time it loops, it delays for 1 second and increments the value stored at
the address stored in p. Every print statement also prints the PID (Process
Identifier) for the program. This PID is unique per running process.
Each process has its own private virtual address space (also known as its
address space), which the operating system (OS) maps into the machine’s
physical memory.
Initial value : 0
Final value : 2000
Because each thread increased the counter 1000 times, the counter’s final
value is 2000 when the two threads are done. Indeed, if the loops’ input
value is set to N, we should anticipate the program’s ultimate output to be
2N. But, as it turns out, life is not so easy. So let’s rerun the same program,
but this time with larger loop values to see what happens. Run the
following program 3 or 4 times and note the output.
./thread 100000
Are the outputs what you expect? Why do you think this is happening?
The results are related to the execution of the instructions one by one. A
crucial part of the program takes three instructions to increment the
shared counter:
one for loading the counter value from memory into a register
one for incrementing it
one for storing it back in memory
Funny things happen because these three instructions do not execute at the
same time. This is a concurrency problem that we will address in the
second course of this certification.
Persistence
Persistence is the specializations’s third main subject and fourth course.
Data in system memory can be easily lost due to volatile storage technology
like DRAM. When power is off, or the system crashes, all data in memory is
lost. As a result, we require hardware and software to store data
persistently, which is important for any system since users value their
data.
The hardware is an input/output (I/O) device. Hard drives are popular for
storing long-term data, but so are SSDs.
The file system is the part of the operating system that handles the disks. It
is responsible for storing user files reliably and efficiently.
Unlike the OS’s CPU and memory abstractions, the OS does not create a
private, virtualized drive for each program. Instead, users are expected to
share file-based information regularly. For example, while writing a C
program, you may use an editor (like Emacs7) to create and change the C
file (emacs -nw main.c). The compiler may then turn the source code into
an executable (e.g., gcc -o main main.c). When you’re finished, you may
start the new executable (for example,./main).
1. Emacs first generates a file that will be used as input by the compiler;
2. the compiler will then use that input file to create a new executable file
These system calls are routed to the file system part of the OS. The
filesystem then handles the requests and returns a response code to the
user.
Figuring out where on disk this new data will live, and
We will explore devices, I/O, and file systems in much more detail in the
certification course on Persistence.
Design Goals
Now, we should have an idea of what an OS does.
Since we want to build OS’s we want to focus our design goals and make
necessary trade-offs for the most efficient system.
Isolation is the core of protection, and accounts for a lot of what the
OS has to do.
The OS will have various goals depending on how the system is used and
will likely be built in slightly different ways. It’s okay though, because many
of the ideas we will explore on creating an OS apply to a wide range of
devices.