Operating System Flashcards
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.
Situation of Deadlock
Mutual Exclusion - one resource must be held at non-sharable mode.
Hold and Wait - process must hold one resource and wait for another.
Non - Premptive
Circular wait
Deadlock Handling Methods
Prevention - designing a possible system with no possiblity of deadlock.
Avoidance
Detection
Ignorance
Fork
a fork is when a process (running program) creates a new copy of itself. The new process (called the child process) is nearly identical to the original process (parent process), but has its own unique process ID and can execute independently.
Thread
A thread is the smallest unit of execution within a process. It’s like a lightweight sub-process that shares the same memory space as its parent process.
the main components and concepts of threads:
Thread ID:
Program Counter: Keeps track of which instruction is currently being executed by the thread.
Stack:
Register Set: Contains thread-specific registers including:
Program counter
Memory Hierarchy
Register
Cache
Main Memory
Magnetic Disk
What are the different kinds of operations that are possible on semaphore?
There are basically two atomic operations that are possible:
Wait()
Signal()
What is a bootstrap program in OS?
It is generally a program that initializes OS during startup i.e., first code that is executed whenever computer system startups. OS is loaded through a bootstrapping process or program commonly known as booting. Overall OS only depends on the bootstrap program to perform and work correctly. It is fully stored in boot blocks at a fixed location on the disk. It also locates the kernel and loads it into the main memory after which the program starts its execution.
Explain demand paging?
Demand paging is a method that loads pages into memory on demand. This method is mostly used in virtual memory. In this, a page is only brought into memory when a location on that particular page is referenced during execution. The following steps are generally followed:
Attempt to access the page.
If the page is valid (in memory) then continue processing instructions as normal.
If a page is invalid then a page-fault trap occurs.
Check if the memory reference is a valid reference to a location on secondary memory. If not, the process is terminated (illegal memory access). Otherwise, we have to page in the required page.
Schedule disk operation to read the desired page into main memory.
Restart the instruction that was interrupted by the operating system trap.
What do you mean by process synchronization?
Process synchronization is basically a way to coordinate processes that use shared resources or data. It is very much essential to ensure synchronized execution of cooperating processes so that will maintain data consistency. Its main purpose is to share resources without any interference using mutual exclusion. There are two types of process synchronization:
Independent Process
Cooperative Process
What is thrashing in OS?
It is generally a situation where the CPU performs less productive work and more swapping or paging work. It spends more time swapping or paging activities rather than its execution. By evaluating the level of CPU utilization, a system can detect thrashing. It occurs when the process does not have enough pages due to which the page-fault rate is increased. It inhibits much application-level processing that causes computer performance to degrade or collapse.
What is a socket, kernel and monolithic kernel ?
Socket:
A socket is defined as an endpoint for communication, A pair of processes communicating over a network employ a pair of sockets ,one for each process. A socket is identified by an IP address concatenated with a port number.
The server waits for incoming client requests by listening to a specified port. Once a request is received, the server accepts a connection from the client socket to complete the connection.
Kernel is the central core component of an operating system that manages operations of computer and hardware. Kernel Establishes communication between user level application and hardware. Manages memory and CPU time. Decides state of incoming processes. Controls Disk, Memory, Task Management
Monolithic Kernel (provides good performance but lots of lines of code)
It is one of the types of kernel where all operating system services operate in kernel space. It has dependencies between system components. It has huge lines of code which is complex.
Example : Unix, Linux, Open VMS, XTS-400 etc.
Explain zombie process?
Zombie process, referred to as a defunct process, is basically a process that is terminated or completed but the whole process control block is not cleaned up from the main memory because it still has an entry in the process table to report to its parent process. It does not consume any of the resources and is dead, but it still exists. It also shows that resources are held by process and are not free.
What is the difference between paging and segmentation?
Paging divides physical and logical memory into fixed-size blocks called pages (physical) and frames (logical). Pages are typically small (4KB-16KB) and allow fine-grained memory allocation. The system maintains a page table to map logical pages to physical frames.
Segmentation divides memory into variable-sized blocks called segments, based on logical program units like code, data, and stack. Each segment has a base address and length. The system uses a segment table to track segment locations and enforce protection.
What is virtual memory?
A computer can address more memory than the amount physically installed on the system. This extra memory is actually called virtual memory and it is a section of a hard disk that’s set up to emulate the computer’s RAM.
The main visible advantage of this scheme is that programs can be larger than physical memory. Virtual memory serves two purposes. First, it allows us to extend the use of physical memory by using a disk. Second, it allows us to have memory protection, because each virtual address is translated to a physical address
What do you mean by Belady’s Anomaly?
In the Operating System, process data is loaded in fixed-sized chunks and each chunk is referred to as a page. The processor loads these pages in the fixed-sized chunks of memory called frames. Belady’s Anomaly is a phenomenon in which if we increase the number of frames in memory, then the number of page faults also increases. It is generally experienced when we use FIFO (First in First out) page replacement algorithm.
What is spooling in OS?
Mechanism that handles slow I/O devices by buffering data in a temporary storage area in secondary memory (called a spool) for processing multiple I/O requests asynchronously. This allows programs to write output to the spool rather than directly to the device, enabling concurrent processing of CPU operations and I/O operations.
What are various sections of the process?
There are basically four sections in the process as given below:
Stack: It is used for local variables and returns addresses.
Heap: It is used for dynamic memory allocation.
Data: It stores global and static variables.
Code or text: It comprises compiled program code.
What is fragmentation? Types of fragmentation.
An unwanted problem in the operating system in which the processes are loaded and unloaded from memory, and free memory space is fragmented. Processes can’t be assigned to memory blocks due to their small size, and the memory blocks stay unused. It is also necessary to understand that as programs are loaded and deleted from memory, they generate free space or a hole in the memory. These small blocks cannot be allotted to new arriving processes, resulting in inefficient memory use.
The conditions of fragmentation depend on the memory allocation system. As the process is loaded and unloaded from memory, these areas are fragmented into small pieces of memory that cannot be allocated to incoming processes. It is called fragmentation.
Types of fragmentation:
1. Internal
2. External
What is spooling ?
Spooling is a process in which data is temporarily held to be used and executed by a device, program, or system.
In spooling, there is no interaction between the I/O devices and the CPU. That means there is no need for the CPU to wait for the I/O operations to take place. Such operations take a long time to finish executing, so the CPU will not wait for them to finish.
The biggest example of Spooling is printing. The documents which are to be printed are stored in the SPOOL and then added to the queue for printing. During this time, many processes can perform their operations and use the CPU without waiting while the printer executes the printing process on the documents one-by-one.
Differenence between Semaphore and Mutex ?
Mutex (Mutual Exclusion):
Definition: A lock that can only be used by one thread at a time, like a bathroom with a single key.
Think of it like a bathroom key:
Only one person can have the key and use the bathroom at a time
The same person who locked must unlock it
Key can be either available (1) or not available (0)
Semaphore:
Definition: A counter that can allow a fixed number of threads to access a resource, like a bathroom that can fit 3 people.
Think of it like a bathroom counter:
Can allow multiple people (value can be > 1)
Anyone can enter if space is available
Anyone can leave and make space for others
Counter shows how many spots are left
Explain Cache
Cache memory is an extremely fast memory type that acts as a buffer between RAM and the CPU. It holds frequently requested data and instructions so that they are immediately available to the CPU when needed.