0% found this document useful (0 votes)
8 views3 pages

Experiment 10 (OSII)

The document outlines various memory management techniques in the Unix Operating System, including virtual memory, paging, swapping, overlays, and memory protection. It provides theoretical explanations and practical demonstrations through code examples for paging and swapping. The aim is to educate on how these techniques enhance memory utilization and process management in Unix.

Uploaded by

devab52664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Experiment 10 (OSII)

The document outlines various memory management techniques in the Unix Operating System, including virtual memory, paging, swapping, overlays, and memory protection. It provides theoretical explanations and practical demonstrations through code examples for paging and swapping. The aim is to educate on how these techniques enhance memory utilization and process management in Unix.

Uploaded by

devab52664
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 10

Title: Study and demonstration of different Memory Management Techniques.

Aim: To Learn About different Memory Management Techniques in Unix Operating System.

Theory: Write a theory about different Memory Management Techniques in Unix Operating
System.

//Write as it is given below

1. Virtual Memory:
 Central to memory management in Unix is the concept of virtual memory. This technique
creates the illusion of a larger contiguous memory space for a process than physically
available RAM.
 Virtual memory combines physical RAM and disk space (swap space) to provide this
illusion. The Memory Management Unit (MMU), a hardware component, translates virtual
addresses used by the process into physical memory addresses.
 Benefits:
 Allows processes to be larger than physical memory.
 Enables running multiple processes concurrently.
 Simplifies memory allocation for programmers as they don't need to worry about
physical memory constraints.
2. Paging:
 A core technique used to implement virtual memory.
 Divides both physical memory (RAM) and logical memory (process address space) into
fixed-size blocks called frames and pages, respectively.
 A page table maintained by the MMU keeps track of the mapping between virtual pages and
physical frames.
 Only the required pages of a process are loaded into RAM, promoting efficient memory
utilization.
 Advantages:
 Eliminates internal fragmentation, a common issue with contiguous memory
allocation.
 Provides flexibility in memory allocation as pages don't need to be contiguous.
3. Swapping:
 Another technique employed by Unix for memory management.
 Involves temporarily moving inactive processes or entire process page sets from RAM to
swap space on disk.
 This frees up physical memory for more active processes.
 When a swapped-out process becomes active again, its pages are loaded back into RAM
from the swap space.
 Swapping complements paging by allowing the OS to run more processes than can fit
in physical memory at once.
4. Overlays (Optional):
 An older technique, less commonly used in modern Unix systems.
 Suitable for very large programs that cannot fit entirely in memory.
 Divides the program into smaller, logical segments called overlays.
 Only the currently needed overlay is loaded into memory, and overlays are swapped in and
out as required during program execution.
5. Memory Protection:
 A crucial aspect of memory management to ensure process isolation and prevent programs
from corrupting each other's memory or the kernel's memory space.
 Unix utilizes memory protection mechanisms provided by the hardware (MMU) to define
read-only, read-write, and execute permissions for different memory regions.

Problem Statement: Demonstrate different Memory Management Techniques in Unix Operating


System.

1) Paging

#include <stdio.h>

#define MEMORY_SIZE 1024 // Simulate memory size in bytes


#define PAGE_SIZE 32 // Simulate page size in bytes

int memory[MEMORY_SIZE];

void allocate_page(int process_id, int page_number) {


int frame_number = page_number * 10; // Simulate fixed mapping (replace with logic)
if (memory[frame_number] == 0) {
memory[frame_number] = process_id;
printf("Allocated page %d of process %d to frame %d\n", page_number, process_id,
frame_number);
} else {
printf("Frame %d already allocated!\n", frame_number);
}
}

int main() {
allocate_page(1, 0);
allocate_page(2, 1);
allocate_page(1, 2); // Simulate allocation failure
return 0;
}

2) Swapping

#include <stdio.h>

int ram[100];
int disk[200];
void swap_out(int process_id) {
// Simulate copying data from RAM to disk for process_id
printf("Swapping process %d out to disk\n", process_id);
for (int i = 0; i < 100; i++) {
disk[i + process_id * 100] = ram[i];
}
// Clear RAM for swapped-out process (not shown for simplicity)
}

void swap_in(int process_id) {


// Simulate copying data from disk to RAM for process_id
printf("Swapping process %d in to RAM\n", process_id);
for (int i = 0; i < 100; i++) {
ram[i] = disk[i + process_id * 100];
}
}

int main() {
swap_out(1);
swap_in(1);
return 0;
}

//Attach two prints of output along with program one for paging and another one for
swapping
Conclusion.

You might also like