Posts

FCFS and SJF

Image
CPU Scheduling in Operating Systems: In the context of operating systems, CPU scheduling involves determining which process (or task) should be executed next by the central processing unit (CPU). The goal is to maximize CPU utilization, minimize waiting time, and ensure fair allocation of resources. Various scheduling algorithms are used to achieve these objectives. First-Come-First-Serve (FCFS) Scheduling: Definition: FCFS is the simplest CPU scheduling algorithm. It is non-preemptive, meaning once a process starts executing, it cannot be interrupted until completion. Processes are placed in a queue based on their arrival time. The process that arrives first gets executed first. Execution Order : Processes are executed in the order they arrive. The process at the front of the queue is selected for execution. Advantages: Easy to implement. Minimal overhead. Disadvantages: Often results in long waiting times. Leads to the convoy effect (where a long process holds up other processes). Sh...

Memory Allocation Scheme- First Fit , Worse Fit, Best Fit

Let’s delve into the memory allocation methods for fixed partitions: First Fit, Worst Fit, and Best Fit. First Fit Allocation: In this technique, the operating system searches through the list of free memory blocks, starting from the beginning, until it finds a block large enough to accommodate the memory request from a process. Once a suitable block is found, it is split into two parts: the portion allocated to the process and the remaining free block. Advantages: Simple and efficient search algorithm. Minimizes memory fragmentation. Fast allocation of memory. Disadvantages: Poor performance in highly fragmented memory. May allocate larger blocks than needed, leading to inefficient memory utilization. Example: Consider allocating processes with sizes 212K, 417K, 112K, and 426K to memory blocks of sizes 100K, 500K, 200K, 300K, and 600K respectively: Process 1: Allocated to Block 2 (size 212K). Process 2: Allocated to Block 5 (size 417K). Process 3: Allocated to Block 2 (size 112K). Pro...

Shared Memory Inter-Process Communication ( IPC)

Shared memory Inter-Process Communication (IPC) in Linux allows processes to communicate by sharing a region of memory. This method is efficient because it avoids the overhead of copying data between processes. Here's how shared memory IPC is typically done in Linux: Create a Shared Memory Segment: To use shared memory IPC, you need to create a shared memory segment. This is done using the shmget() system call, which allocates a new shared memory segment or obtains the identifier of an existing one. You specify the size of the shared memory segment and some permissions. Attach the Shared Memory Segment: Once you have obtained the identifier for the shared memory segment, you need to attach it to the address space of your process. This is done using the shmat() system call. This call returns the address of the shared memory segment in your process's address space. Accessing the Shared Memory: After attaching the shared memory segment to your process's address space, you c...

Page Replacement Algorithms

In an operating system that uses paging for memory management, page replacement algorithms come into play when a new page needs to be loaded into memory, but there are no free page frames available. These algorithms decide which existing page should be replaced to accommodate the new one. Let’s delve into some common page replacement strategies: First In First Out (FIFO) Principle: FIFO follows a straightforward approach by replacing the page that entered memory first. This is the simplest algorithm. The operating system maintains a queue of all pages in memory, with the oldest page at the front. When a page fault occurs (i.e., a requested page is not in memory), the page at the front of the queue is selected for replacement. Imagine a queue where pages enter from one end and exit from the other. FIFO replaces the page at the front of the queue when needed. Example: Consider a page reference string: 1, 3, 0, 3, 5, 6, 3 with 3 page frames. The resulting page faults are as follows: Initi...