Lecture 1
There are 5 project grace days, which are classic CS style grace days
The stack is faster to access than the heap
The heap and stack grow in different directions
AT&T Archives: The UNIX Operating System
- Novel ideas from UNIX
- If I type the name of a file, have the shell treat it as a command
- I/O redirection allows you to create a pipeline of commands, one into another
- "input/output redirection is handled not by the program, but by the shell"
- "peripherals like the printer and disk drive are treated as files"
sort | uniqcommand > out.txtcommand < in.txt
- A file is just a location in memory, and a size in bytes
OS Challenges
- Reliability
- Availability
- Security
- Performance
- Latency
- Throughput
- Overhead
- Fairness
- Predictability
- Portability
Process
- A process is launched by running an executable program
- A process is an instance of a program
- There are two main components of a process
- Address Space
- Code
- Data
- Stack
- Heap
- Kernel Stack
- State
- Process Control Block
- Registers
- Program Counter
- List of Open Files
- Address Space
Stack & Heap
- Stack and Heap grow in opposite directions
- The stack is faster to access than the heap
- The stack is in charge of the recursive function calls and statically allocated data
- The heap is in charge of dynamically allocated memory at runtime
xv6 Process States
proc.h:
enum procstate {UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE};
System Calls
A system call is the interface between a user app and a service provided by the OS
- A system call is basically the OS's API (e.g.
libc)
- A system call is basically the OS's API (e.g.
Examples
- POSIX API for POSIX systems (macOS)
- Java API for Java JVM
Processes
A process is an instance of a program, it is instantiated by being executed, and it runs with limited rights. They are started by opening an exectuable file
Differences between programs and processes:
- Programs are static, processes are dynamic
- One program can be several processes
- Programs exist, but processes are an abstraction created by the operating system
There are two main components of a process:
- Address space, includes
- Code
- Data
- Stack
- Heap
- Kernel stack
- State: includes
- Managed by the process control block or PCB,
- Resides in the kernel address space
- Includes the following components:
- Registers
- Program counters.
- A list of files that are currently opened
Address Space Abstraction
Protection via process isolation is one the key principles of building reliable systems is isolation of processes in order to provide protection.
Address space is an abstraction of physical memory created in order to create a sandbox for each process. Each process has its own little playful sandbox where it has its own code, data, and stack.
This is a joint effort by hardware and the operating syystem.
- The operating system allocates physical memory
- The hardware performs address translation, converting user addresses to physical addresses
The operating system, for its own protection, has its own address space
Process Address Space
- The only memory accessilbe to a process is that which lies in its address space
Invoking functions
The Computer Systems textbook has a good section on translating a function call. There's also good material about this in your CSCI 353 textbook: "Computer Systems: A Programmer's Perspective"
Untangling stack and heap, and static vs. dynamic memory. A stack pointer, local variables are stored on the stack, a data structure which supports push and pop operations in a LIFO order. Called functions are pushed by the compiler, which is called the frame.
States of a process
In xv6, the states of a process are as follows, as declared in proc.h
`enum procstate {UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE};
- Embrio
- Runnable
- Running
- Sleeping
- Zombie
More commonly, those processes are referred to as, in order:
- New
- Ready
- Running
- Waiting
- Finished
A zombie state is a special case, when a process terminates because there are no more processes to be executed, but the process remains in the PCB table. This is commonly found when a parent created a child process, and needs to follow the state of the child process for its own execution.
Questions
Question 1
Apple is releasing a car. Will it have windows?
Question 2
Which of the following tasks would require OS support?
- Input a character from the keyboard: yes
- Invoke a high-level matrix multiplication operation: no
- Allocate
nbytes of memory for a new data structure: yes - Load a program into memory: yes
- Change the layout of a document: no
- Call a library function: yes
- Call a function defined within the current program: no
- Exit the current program: yes
- Sleep for
nseconds: yes
Question 3
Think about the difference between system reliability and availability:
- Give an example of a system which is reliable but not available The train station by my house has trains that always arrive directly on time, but only arrive a few times a day. They leave shortly thereafter, so the majority of the time, there is no train availbale to those sitting at the train station.
- Give an example of a system which is available but not reliable When renting a place to stay through AirBnB, you can be assured that you will be able to find a place to stay, whenever it is you want to stay there. Upon your arrival, however, you may find your appointment is abruptly cancelled, or your stay is cut short by an emergency maintenance.
Question 4
- Why do the stack and the heap grow in opposite directions? It optimizes the amount of space used without overlap.
- Which is faster to access: the stack or the heap? The stack, because it's just a derefencing of a pointer. The heap, on the other hand, has a more complex implementation, which involves a higher overhead, from actions such as allocating memory and deallocating memory.
Question 5
Check whether the stack grows downward or upward
void fun(int *main_local_addr) { int fun_local; printf("Stack grows... "); if (main_local_addr < &fun_local) { printf("upward!n"); } else { printf("downward\n"); } } int main() { int main_local; fun(&main_local); }
Question 6
True or false:
- An OS uses a PCB to represent a process:
- false: the PCP represents metadata about a process.
- The PCB is created by the process when execution starts
- false: it is created by the operating system
- The PCB is becomes part of the process being executed
- false: it is part of the operating system, or else a process could modify its own process control.
- Two processes can be executing the same program:
- true
Question 7
Missing...
Question 8
Part A:
- CPU state
- process state
- open files
- children
Part B:
- Actually, the CPU state will change
- Process state will not change
- Open files may change
- Parent may not change
- Children may change