Operating System Flashcards
(45 cards)
What is an operating System
It act as an intermediate between hardware and software, Resource Manager/Allocator,
Two goals
1) Provide convenience
2) Effiniency (Using resouce in an efficient manner)
Functions of OS
Process Management, File Management, I/O management, Memory Management.
Multiprogramming
Keep several Jobs in main memory simultaneously, allowing more efficient CPU utilization, if once job is waiting for some input output operation we can switch to another process in the mean time.
Multitasking
All the process are run for a fixed interval of time than we switched to another process, the context switching is so fast it feels like we are doing multiple task at same time.
Multiprocessing
We have multiple CPU in a single device, concurrent process run in separate CPU, achieve true parallelism.
System Call
programmatic way for an application program to request a service from the kernel of the operating system. It acts as a bridge between user space and kernel space,serving as the fundamental interface between a process and the operating system.
Program and Process
Program is a passive entity, a list of instruction stored on disk,
Program becomes process when an executable file is stored in the main memory.
Process is an active entity which requires resources like main memory, Cpu register and system buses.
Process memory section
Memory Sections:
Stack:
Contains temporary data
Function parameters
Return addresses
Local variables
LIFO (Last In First Out) structure
Heap:
Dynamically allocated memory
Managed by programmer
Used for dynamic data structures
Memory allocated during runtime
Text/Code Section:
Program instructions
Read-only
Shared among processes
Contains executable code
Data Section:
Global variables
Static variables
Initialized data
Uninitialized data (BSS)
PCB
A Process Control Block (PCB), also known as a Task Control Block, is a data structure in an operating system that contains all the information needed to manage and keep track of a specific process.
Process ID (PID): Unique identifier
Process State: Running, Ready, Blocked, etc.
Program Counter: Address of next instruction
CPU registers: Contents of processor registers
Memory management info: Memory allocation details
Scheduling information: Priority, CPU usage time
I/O status: List of allocated I/O devices
Process State
- New state
- Ready state
- running state
- waiting state
- terminate state
Schedulers and It’s types
Process migrates among various scheduling queue through it’s lifetime. Operating system decide from which queue to which queue process will move.
Long term Scheduler - which process enter the ready state from job pool.
Medium term. scheduler - maintain the degree of multiprogramming by swapping process in and out of the memory.
Short term scheduler - decide which process will move from ready to running state
Context Switching
Switching from one process to another, when a process is switched kernal save the state of current process to PCB, and restore the state of the new process from PCB.
Types of Scheduling algorithms
1 Non - Pre-emptive - Once the process is alocated to CPU. it keeps the CPU, until it get executed.
2 Pre-emptive - Process can be interrupted and moved to ready queue.
Throughput
the number of process executed per unit time.
Different terminologies used in scheduling
1 Arrival Time - the time at which process enter ready queue.
2 Burst Time - the time it require in cpu.
3 Completion Time - the time of completion
4 Turn around Time - completion time - arrival time
5 Waiting Time - TAT - CT
FCFS (First come first serve)
Non-Premptive
Convey effect -> smaller process have to wait more for cpu.
SJFS (Shortest Job first serve)
disadvantage -> Starvation
Ageing
gradually increasing the priority of process which are in system for a long time.
Race Condition
A race condition occurs when multiple processes or threads access and manipulate shared resources (like memory, files, or devices) simultaneously, and the final outcome depends on the particular sequence or timing of their execution.
Critical Section
A critical section is a segment of code where a process accesses shared resources (like variables, files, I/O devices) that cannot be accessed simultaneously by other processes. Think of it as a “do not disturb” zone where only one process can execute at a time to maintain data consistency.
Criteria to solve critical section problem
Mutual Exclusion - No two process should be present inside the critical section at same time.
Progress - prevent deadlock
Bounded Weight - here must exist a bound ‘k’ such that if a process P is requesting entry to its critical section at time t, then at most k other processes can enter their critical sections before P’s request is granted.
Peterson’’s Solution
Solve critical section problem for two process.
P1
while(1){
flag[0] = true;
turn = 1;
while(flag[1]==true&&turn==1)
CS
flag[0] = false;
}
P2
while(1){
flag[1] = true;
turn = 0;
while(flag[0]==true&&turn==0)
CS
flag[1] = false;
}
Semaphores
A semaphore is a synchronization mechanism used in operating systems to control access to shared resources among multiple processes or threads. It’s like a traffic signal that manages access to prevent conflicts.
Sempahores can be divided into two types
1 counting sempahore(two atomic operation wait(x),signal(x))
2 binary semaphore
Deadlock
A deadlock is a situation in an operating system where two or more processes are blocked forever, each waiting for resources that are held by other processes in the same group. It’s like a circular waiting situation where no process can proceed.