OS Quiz 2 Flashcards
Boot Sequence Order
ROM BIOS POST Primary Master HD
BIOS tells where the Master Hardrive is Need to know where master HD is because that loads the Boot Block/Sector = 512bytes = Master boot Record (MBR)
• Multi-Programming
o Purpose is to maximize CPU usage
o Ability to run multiple programs concurrently
o Must be efficient (most important factor)
o Fair – resources must be allocated equally across the system
process
• Process
o Running program / program in execution
o AKA Task
process address space
Process Address Space • Address space for every process in memory • bss & data, global variables • dynamic data = creating new object / can grow and shrink as we create and release methods/objects • bottom of stack address is static Stack btm top Local variables – dynamic Heap “new” - dynamic bss Uninitialized (int x) Data Initialized (int x = 5) Text Code
Process States / Transitions Diagram
• New State (request has been sent, OS checks stuff before executing)
• Admit Transition (process is admitted to the system / set up is done/ allocate memory)
o Address and PCB given to process
• Ready State
• Dispatch Transition (dispatched into the CPU)
• Running State (process can be running, CPU is actively running program)
• Exit Transition
• Terminated State (process still exists in system but is not actively running)
• Suspend Transition (always when going to suspend state)
• Resume Transition (when coming out of suspend into ready state)
See graph
Process control block
PID: Process ID
State: What is the current state of the process?
PC – Program Counter: What are we doing? / Point of execution?
CPU Registers: The values in the registers
Scheduling
Memory Management Info: Where is the process address space existing in the physical memory
I/O Information All resources involved in process (ex: if opening file, must know about it)
Accounting Resource accounting – maintenance information about the process. Memory, CPU cycles, usage
Degree of Multiprogramming
o How many programs can we execute at the same time?
o Simulating concurrency in multiprogramming with time sharing
Sharing time of CPU across system
• Context Switch
o Process 1 interrupts CPU and says “hey I need to execute! Look at me”
o Interrupt gets sent to the OS
o OS saves the PCB (process control block) of Process 0
o OS loads PCB from Process 1
o OS can then execute
o Saves the PCB and returns to Process 0 and loads it’s PCB
o Switching from Process 0s “saving PCB” to Process 1’s “loading PCB” is a context switch
o Context switch is how we achieve Time Sharing
Process Queues
Ready Queue – waits on the CPU
Disk Queue – Waiting on hard drive
Disk Queue 2 – waiting on other hard drive
Waiting Queue
Ready Queue = essentially a list of all the PCB processes that are in the ready state
Process Schedulers
- Long-term / Admission Scheduler
a. Doesn’t run often
b. Admitting transition (new to ready state)
c. Decides on the degree of multiprogramming
i. How many processes system can handle at any given time
d. Windows/Linux do not have scheduler
i. Don’t handle degree of multiprogramming
ii. End users control this - Short-term / CPU Scheduler
a. Runs very frequently
b. Responsible for choosing the process from the ready queue to be dispatched into CPU - Medium-term / Swapper
a. Responsible for the suspension and resuming of processes
Signals
• an event on I/O (example: I’ve typed a letter on the keyboard in notepad, “a” gets sent as a signal from the O/S)
• Windows calls signals: Asynchronous Procedure Call (APC)
• 3 different ways to handle a signal:
o Default Handler – OS
Do what the OS tells you to do
o Ignore the Signal
o Custom handler / user – defined
User = programmer defined (listeners / executing methods)
Callbacks
Method that gets called when OS sends a signal
Process Creation
• Embedded systems do not have this ability to dynamically create processes • Double click program = new state o Allocate address space o PCB o Insert into ready Queue • Parent Process o Child are any new processes that occur o Desktop process (parent) open Word(child of desktop) open eclipse (child of desktop) JVM (child of eclipse) java program helloworld.java (child process of JVM) • Process 0 (PID=0) o Very first process in the system o Windows – System Idle Process o Linux – System Process
Parent Responsibilities
• Validation: sufficient resources, privileges to run child process
1. Get resources from OS directly
2. Share resources from parent
What happens to parent when child runs?
1. Wait for child to terminate
a. Parent/Child has dependency
b. Ex: helloworld.java runs, JVM has to wait till helloworld completes, then JVM cleans up and shuts down.
2. Continue Execution
When creating the Child address space, we can create an exact copy of parent, same text/data/bss/heap/etc… as parent. Or a brand new one with nothing in it.
• Copy of parent (faster) (Linux – fork())
o Child is a copy (address space)
o Allows us to share data between parent and child (bss/data)
o Running exact same program (inherit the text/code)
• Brand New (Windows –createProcess())
o Do not inherit shared variables
o But we get new code / no shared text
• Parent keeps track of PID so that it can continue to be responsible for the child.
• Parent is responsible for clean up
o When child dies, it cleans up.
o During the terminated state of the child the child is called a Zombie
Process terminates when:
• Last line of code completes (exit)
• Forced by OS
• Forced by User
o Other processes
Parent can kill child when:
- Exceeded Resources
- Child has done its job so we don’t need it anymore.
- Parent is terminating.
a. A dependency: cascading termination
i. Parent is terminating and tells each of its children to go “kill yourself”
b. No dependency (if we open notepad from command line…notepad can run without cmd open)
i. Kill the parent, the child becomes an orphan
ii. Orphan gets adopted by process 0 (no longer an orphan! Yaaaay)
process termination cleanup
Clean up
• deallocating address space
• release instance of the PCB
• Parent can then check that child has completed deallocation and release PCB, parent will then remove the reference to the child.
Difference between process and thread
Process – Single point of execution
• Program Counter
Threads – Multiple points of execution
• Program Counter per thread
• Light weight process (see TCB), process is “heavy weight” (PCB)
o Specific to amount of resources that a thread needs
What is TCB
Thread Control Block (TCB) • System uses this to keep track of all the threads • Control block is smaller than the PCB State TID (thread ID) PC (program Counter) CPU Registers Scheduling
Process vs Threads
• Thread
o Less resources
o Context switch: faster
o Less information to save, load and maintain
o Share data
Address space is shared between all threads
Chrome tabs: each one is its own process, websites can’t interfere with other tabs
o Share resources
Ex: Microsoft word, window is shared resource
• Processes
o Built in protection
Every process has own address space and can’t access another processes space
o Not parallel
We don’t need threads to multitask
Example: autosave happening at same time as spellcheck
Methods/functions may have to run sequentially so no advantage to multithreading them
o Threads share I/O
o Threads are hard