OS - Ch 3,4
Reference : http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf
Process
Process is a running program.
Virtualization runs multiple processes by turns, hence providing a virtual environment that contains multiple number of CPUs
- Context Switch : run & stop …
- Modern OS uses time sharing mechanism which lowers each processors performance.
Scheduling: OS policy to decide run which program at which point.
- Scheduling refers to
- past info: which programs ran for the last one minute
- workload info: what kind of programs ran
- performance measure: system tends to increase communication, workload?
- Scheduling refers to
Definition
- Main components of machine states are:
- Memory: space where instructions and resources are saved/loaded
- Register:
- Program Counter: which instruction is being excuted aka instruction pointer
- Stack pointer: used for managing stack where function varaible and return addresses are saved.
Process API
- Create: OS needs to provide a way to create new process
- Shell, double-click…
- Destroy: Needs to able to forcibly close processes
- Wait: different kinds of process being waited to take turns (wait interface)
- Miscellaneous Control: Pause | resume …
- Status: Interface that provides process status information such as how long has it been running, current stauts…
In-Depth
- OS steps to run a program
- Load program code and static data (initialized variables) into memory (process address space).
- Early OS loaded both program code and static data before executing a program.
- Modern OS loads necessary part of it while running a program.
- Late load requires paging and swapping (later be discussed).
- Memory allocation for run-time stack purpose.
- C uses stack for saving variables, return address…
- OS resets the stack with given parameters especially by using main() function variables argc and argv vectors.
- Memory allocation for heap
- Heap is for saving dynamically allocated data in C; malloc and free.
- Heap is used for linked list, hash table, tree. All the different size (dynamic) data structures.
- Has three file descriptors - FOR I/O
- STDIN
- STDOUT
- STDERR
- Now ready to execute the program
- Branch to main()
- Load program code and static data (initialized variables) into memory (process address space).
Process Status
- Running
- Ready: Process is ready, but OS is not; executing another process.
- Blocked: Pause the process while waiting for another events; waiting for data
Data Structures
- Register Context: saves register values when the process stopped.
- Once process resumes, use the saved values.
- Process has states such as initial, and final
- Final state: Process is completed, but remain in the memory; useful for parent process to check if the task given to its child is successfully completed.