OS Notes Personal

 Why OS?

1. Resource Management


    It acts as an interface between applications and resources





OS makes sure that memory does not clash between apps





Definition : 




    TYPES OF OS _ MIMP FOR INTERVIEWS



At a time only one process runs, after it finishes, the 2nd process starts.

cons : violation of all 3 Goals

2. Batch Processing OS


cons : violation of all 3 Goals

J4 and J1 will also execute sequentially, so, no as such benefit

If the new job with high priority comes in, it will be in next batch


3. Imp for interview






4. 


Each process will run for 1000ms and then, next one will start the execution


All 3 Goals achieved

5. 





6.



7.



Examples of OS: 









What is Process?







A and B are independent, then, we can execute it in parallel.



Multi- Threading : 







Multi Threading :

Inside a single process, multiple threads completes a task




Multiprocessing : 

many processes p1,p2 are running on diff CPUs.

4 core cpu means 1 physical cpu and inside that 4 logical cpus



Multitasking : 

when one process goes for I/O, other process starts

- cpu always have some task, it never sits free


Multiprogramming : 

Lecture 4 : 










directory is a tree data structure




I/O operations : it is just devices like external mouse, pendrive, printer


User mode and Kernel Mode : 




Types of Kernel : 



everything is in one place, so faster operations










Lecture 5 : 












Lecture 7 : 

How operating system starts/Boots Up??











32 bit vs 64 bit




Lecture 9








Attributes of process : 



Process Life cycle:



JOB SCHEDULAR : fetch the process from disk and put it in ready queue.



CPU SCHEDULAR : ready to running state


LTS : long term schedular - works after an interval of time - it handles multi programming

STS : this schedular works very frequently



how does od handles orphan processes?

- if the actual parent is dead, it will make init as a parent to all child processes without parent

Zombie Process : 

parent wait for 5 sec to let child finish

child finishes in 2 sec.

So, during this 3 sec, child process stays in process table and is considered zombie


max no of processes : 

Windows: Windows Operating System limits the number of process table entries to 65536. Linux: The maximum number of process table entries in Linux varies based on the distribution, architecture and kernel version. In general, it ranges from 32768 to 4194304

Non-Preemptive Scheduling

In non-preemptive scheduling, once a process starts using the CPU, it runs until it finishes or moves to a waiting state. The OS cannot forcibly take away the CPU.

Preemptive Scheduling

In preemptive scheduling, the operating system can interrupt a running process to allocate the CPU to another process usually due to priority rules or time-sharing policies.A process may be moved from Running → Ready state before it finishes.

    


TAT : turn around time

WT : wait time





this would have been better:


if heavy job comes first, rest have to wait a lot, this is called as convoy effect



shortest Job First :

Non -preemptive SJF




    Preemptive SJF :






SJF is less practical, because we don't always no the correct BT


Non -preemptive Priority scheduling :





Preemptive priority :




convoy effect for short job in this case.


one problem is there :

if we keep on pushing jobs in ready queue, maybe a lowest priority job can go to infinite waiting.


Solution to infinite waiting = Ageing



Round Robin : 

- most popular

- lowest starvation

- no convoy effect


Cons: 

- too much context switching and overhead(overhead means any other process other than actual code logic, such as time based process switching, more time quantum means less overhead)











preemptive priority is set between all 3 queue







each process has its own individual address space, but multiple threads shares the same address





Crtitical Section Problem / Race Condition : 



11+4 = 15 should be there, but its 11+1=12 only for each req










search on google : conditional variable and semaphore

Producer - Consumer Problem  :







Reader-writer Problem













dining philosopher problem

- each person needs at least 2 forks to eat noodles










Deadlock : 














cycle but no deadlock




deadlock prevention : 









Deadlock avoidance : 




Banker's Algo to avoid deadlock : 










if p3 would have needed 8 resources, system would have gone into unsafe state/deadlock.









rn , t1,t2,t3 running parallely, but i want t1->t2->t3



Memory Management

1. Why do we need logical address?



P2 was running on 65, but it got overwritten by P1

Solution?

We assign logical address to each process, and then map logical addresses with physical address.

















FS= Free Space


















📍 Where is the page table stored?

The page table is stored in main memory (RAM) — not in the CPU.

That means:

  • Each memory access would require another memory access just to translate the address!

  • So every instruction that touches memory (like mov, load, etc.) would effectively double the memory traffic.

⚡ Enter the TLB (Translation Lookaside Buffer)

The TLB is a small, hardware cache inside the CPU’s Memory Management Unit (MMU).

It stores recently used virtual-to-physical address translations:

Virtual Page NumberPhysical Frame Number

So next time the same virtual page is accessed, the CPU can:
✅ Skip the page table lookup
✅ Instantly get the physical address from the TLB




Problem with paging
    


this causes overhead and thus in-efficient.










keeps currently active page in actual physical memory and inactive page in disk, then, swaps when the current page is done or inactive.









What is page fault?

- we look for page in ram, but it is not there, os needs to fetch it from swap area. this scene is considered as page fault.


Page Replacement Algos:





































if the turn is < 2, oxygent will keep waiting. H will be released

If the turn=2, hydrogen will wait, O is released.




Comments

Popular posts from this blog

Extracting Tables and Text from Images Using Python

Positional Encoding in Transformer

Chain Component in LangChain