Operating Systems Background
Introductions
- introductions of two students
Questions on the readings
The readings today are from Operating Systems: Three Easy Pieces, an open source textbook. You shoud have read these sections:
Key concepts
-
Processes
- processes enable the OS to provide the illusion that the system has an unlimited number of CPUs available, enabling many programs to run “simultaneously”
- a process is a running program: state (registers, stack), memory (address space), I/O
- the OS provides an API so that programs can create, destroy, wait for, and control processes
- processes have a stack and a heap
- a process can be in a variety of states, e.g. ready, running, blocked (e.g. waiting for I/O)
- the OS keeps track of a process using a data structure
-
CPU scheduling
- scheduling algorithm: the part of the OS that decides which process runs and for how long
- can measure effectiveness of a scheduling algorithm with metrics, e.g. turnaround time (time completed - time arrived) or response time (time first run - time arrived)
- see the book diagrams for turnaround time for different scheduling algorithms
- First In, First Out (FIFO) — can lead to long turnaround times if there are long-running processes
- Shortest Job First (SJF)
- Shortest Time-to-Completion First (STCF)
- Round Robin — better for response time
- modern schedulers are much more complex — see multi-level feedback queue in next chapter
-
Address spaces
- the pictures are particularly heplful for this chapter
- early systems let a process use all physical memory not in use by the OS
- modern systems use multi-programming, allowing multiple proceses to be in memory at a time
- each process gets its own virtual address space, with the OS mapping the virtual numbers to physical space
- the OS swaps memory in and out of physical space based on what the running process needs
- the OS uses memory protection so that processes cannot access memory from another process
Class Exercises
Clone the OS homework repo.
Processes
Use cd cpu-intro
to get to the appropriate directory.
This is meant to show you VERY basic CPU scheduling and the how the OS wants balance I/O and CPU.
Run the process simulator from the end of the
Processes chapter. The
-l
flag provides a set of jobs of the form X:Y
, where X
is the number of
instructions and Y
is the percent chance that an instruction is CPU not IO.
The -c
flag computes how the CPU would alternate among proceses, and -p
prints statistics.
Instructions about the CPU scheduling are at the end. Figure out what it will do, then run:
Repeat with:
CPU Scheduling
Use cd cpu-sched
to get to the appropriate directory.
Address spaces
-
Connect to a Linux VPS (e.g. one running on Amazon or Digital Ocean)
-
Look at the man page for
free
. -
Run:
-
Look at the man page for
pmap
-
Run: