Midterm Flashcards
What is the kernel
The core of the OS. The one program running at all times on the computer
Process
A program in execution; instance of a program being executed by OS
3 components of a process
- (code)Executable program
- (data) Associated data needed by the program
- (context) The execution context of the process which contains all information the OS needs to manage the process (ID, state, CPU registers, stack)
What is and where is PCB?
Process Control Block is included in the context, along with the stack
It is snapshot that contains all necessary and sufficient data to restart a process where it left off (ID, state, CPU registers)
- concrete representation of a process
Where in OS is PCB?
It is one entry in the OS’s process table (array of linked list)
What is in user address space of process?
Program code
Data
What is in context of process
PCB
Stack
What are 3 main components of PCB?
Identification
CPU State info (registers, PC, stack pointer)
Control info (Schedule and state info, links to other processes, memory limits, open files)
5 states of process and what they mean
New: process is being created
Ready: The process is waiting to be assigned to a processor
Running: Instructions are being executed
Waiting: The process is waiting for some event to occur
Terminated: The process has finished execution
New to ready process
admitted
Ready to running process
scheduler dispatch
Running to ready process
Interrupt
Running to waiting process
I/O or event wait
Waiting to Ready process
I/O or event completion
Running to terminated process
exit
What is batch system?
A computer system that processes jobs in groups, or batches, without direct user interaction
4 ways a process can be created
System boot
User requests to run application
Existing process spawns a child process
Batch system takes next job in line
3 ways process is terminated
Regular completion, with or without error code
Fatal error (uncatchable of uncaught)
Killed by another process via the kernel
Return value of fork to parent and child
positive value to parent
0 to child
what does execvp do
replace the existing program
Fork example 1
process 13
2 events that lead to process pause/dispatch
- I/O Wait - OS triggered
- Preemptive timeout - hardware interrupt triggered
What 5 things happen when a current process calls create()
- PCB is allocated and initialized
- The parent field of the new process will be set to self (running process)
- new process P is added to the children list of the currently running process
- The new process P is put in ready list
- The scheduler may choose to dispatch to new process or continue the parent
What is and happens during a process context switch
When cpu switches to another process, the system must save the state of the old process and load the saved state for the new process
Is context switching useful work?
No
Is there a difference between a new process and the other processes? can you tell this is a new one?
if OS has a toll how long a process has been run for, but otherwise they are very similar
Process Context Switching 7 steps
- Save cpu context, including PC and registers
- Update process state and other fields of PCB
- Move the PCB to appropriate queue
- Select another process for execution: made by CPU scheduling algorithm
- Update the PCB of selected process (switch to running)
- Update memory management structures
- Restore CPU context to the values contained in the new PCB
What events trigger OS to switch processes? 3
Interrupts
Exceptions
System Calls
Interrupts event
External, asynchronous events, independent of the currently executing process instructions
Exceptions events
Traps, internal synchronous (but involuntary) events caused by instructions: OS may terminate or recover process
System Call events
Traps, voluntary synchronous events calling a specific OS service.
Job queue
Set of all jobs in the system
Ready Queue
Set of all processes residing in main memory, ready and waiting to execute
Device Queue
Set of processes waiting for I/O device
Long term scheduler
The decision to add a program to the pool of processes to be executed (job scheduling)
Medium term scheduling
The decision to add to the number of processes that are partially or fully in main memory (swapping)
Short term scheduling
CPU Scheduling, the decision as to which available processes in memory are to be executed by the processor (dispatching)
Draw scheduler pic
process 31
Long term scheduler controls
the degree of multiprogramming
Which scheduler is invoked more frequently?
Short term scheduler
io bound process vs cpu bound process
io bound spends more time doing io than computations, many short cpu bursts, and vice versa
examples of io bound and cpu bound
chat applications, interactions // photo editors, gaming
What does Long term scheduler have to do
Needs to make careful decisions, decides what comes and stays on system at current time, decides when process terminates
What happens if io scheduled first, what if cpu scheduled first?
- little cpu utilization, and u have many things to do, cpu not fully working
- lost interactivity, io tasks waiting intensively for cpu tasks to finish, even though they only need a little cpu
swapping
memory management technique that temporarily swaps processes from main memory to secondary memory and vice versa, helps increase degree of multi-programming and increase main memory utilization
Mechanisms for processes to communicate and synchronize their actions
Shared memory
Message passing
Shared memory
By using the same address space and shared variables
Message Passing
Processes communicate with each other without resorting to shared variables
Message passing - direct communication
Processes know who they are talking to. They must name each other explicitly
Message Passing - indirect communication
Processes dont know who they are talking to. Messages are directed and received from mailboxes
Message passing - blocking
Synchronous, The sender blocks until the message is received, the receiver blocks until the message is available. Ex:
Message Passing - Non-blocking
Asynchronous, sender send message and continues, receiver receives a valid message or null Ex: streaming service, drone sending signal
What to do with multiple messages
Use Buffer, queue of messages attached to the link, implemented in zero, bounded, or unbounded
Time sharing, each process is given a
Multiple processes running on one physical cpu. Virtual CPU
Virtual CPU
A cpu that the process assumes is available only to itself
Benefits of virtual cpu 3
Multi user support
Multi CPU transparency
Portability
Two ways to organize PCBs
Array of Structures -> wasted memory
Array of pointers to dynamically allocated PCBs -> overhead of dynamic memory management
Waiting list
Contains all processes blocked on a resource
Ready List
Contains all processes that are in ready state and able to run on CPU
A resource is allocated to a process if
the process has access to and is able to utilize the resource
A resource is free if
the resource may be allocated to a requesting process
Scheduler function
Determines which process should run next and starts the process