0% found this document useful (0 votes)
7 views

Os Lab Manual

The document outlines various experiments aimed at practicing basic UNIX commands, shell scripting, and simulating different operating system functionalities. It includes detailed instructions for file and directory management, process management, and system calls like fork and exec, along with examples of simulating UNIX commands such as cp, ls, and grep. Additionally, it covers CPU scheduling algorithms, memory management techniques, file allocation strategies, and page replacement algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Os Lab Manual

The document outlines various experiments aimed at practicing basic UNIX commands, shell scripting, and simulating different operating system functionalities. It includes detailed instructions for file and directory management, process management, and system calls like fork and exec, along with examples of simulating UNIX commands such as cp, ls, and grep. Additionally, it covers CPU scheduling algorithms, memory management techniques, file allocation strategies, and page replacement algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

EXPERIMENT - 1

AIM: PRACTICING BASIC UNIX COMMANDS AND SHELL PROGRAMS

1. Basic UNIX Commands

File and Directory Management

 pwd – Print working directory


 ls -l – List files with details
 cd <dir> – Change directory
 mkdir <dir> – Create a directory
 rmdir <dir> – Remove an empty directory
 rm -r <dir> – Remove a directory with contents
 cp <source> <destination> – Copy a file
 mv <source> <destination> – Move/Rename a file
 rm <file> – Delete a file

File Viewing & Editing

 cat <file> – Display file contents


 less <file> – View file page by page
 head -n <file> – Display first n lines
 tail -n <file> – Display last n lines
 nano <file> or vim <file> – Edit a file

Permissions & Ownerip

 chmod 755 <file> – Change file permissions


 chown user:group <file> – Change file owner
 ls -l – Check file permissions

Process Management

 ps aux – List running processes


 top – Monitor system processes
 kill <PID> – Terminate a process
 fg – Bring a background process to foreground
 bg – Resume a process in the background

Networking

 ping <host> – Check network connectivity


 curl <URL> – Fetch webpage content
 wget <URL> – Download a file
Disk & Memory Management

 df -h – Check disk space


 du - <dir> – Check directory size
 free -m – Check memory usage

2. ell Scripting Practice

Basic ell Script

Write a script to print "Hello, World!"

#!/bin/ba
echo "Hello, World!"

Run: chmod +x script. && ./script.

Looping in ell

#!/bin/ba
for i in {1..5}
do
echo "Iteration $i"
done

If-Else Conditions

#!/bin/ba
echo "Enter a number:"
read num
if [ $num -gt 0 ]; then
echo "Positive number"
else
echo "Negative number or zero"
fi
EXPERIMENT NO: 2

Write programs using the following UNIX operating system calls fork, exec,
getpid, exit, wait, close,stat, opendir and readdir.

1. fork()

Definition:

The fork() system call creates a new child process that runs concurrently with the parent. The
child process gets a copy of the parent’s memory space.

Program:
#include <stdio.h>
#include <unistd.h>

int main() {
pid_t pid = fork(); // Create a child process

if (pid > 0) {
printf("Parent Process: PID = %d, Child PID = %d\n", getpid(), pid);
} else if (pid == 0) {
printf("Child Process: PID = %d, Parent PID = %d\n", getpid(),
getppid());
} else {
printf("Fork failed!\n");
}
return 0;
}

Output:
Parent Process: PID = 1234, Child PID = 1235
Child Process: PID = 1235, Parent PID = 1234

2. exec()

Definition:

The exec() family of functions replaces the current process image with a new process image.

Program (execl())
#include <stdio.h>
#include <unistd.h>

int main() {
printf("Before exec()\n");
execl("/bin/ls", "ls", "-l", NULL); // Replace process with ls command
printf("This will not be printed if exec is successful.\n");
return 0;
}

Expected Output (Directory Listing):


Before exec()
total 12
-rwxr-xr-x 1 user user 1234 Feb 07 12:00 a.out
-rw-r--r-- 1 user user 5678 Feb 07 12:01 program.c

3. getpid()

Definition:

The getpid() system call returns the process ID of the calling process.

Program:
#include <stdio.h>
#include <unistd.h>

int main() {
printf("Process ID: %d\n", getpid());
return 0;
}

Expected Output:
Process ID: 2345

4. exit()

Definition:

The exit() function terminates a process and returns a status to the operating system.

Program:
#include <stdio.h>
#include <stdlib.h>

int main() {
printf("Exiting the program...\n");
exit(0);
}

Expected Output:
Exiting the program...

5. wait()

Definition:

The wait() system call makes the parent process wait until one of its child processes terminates.

Program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main() {
pid_t pid = fork();

if (pid > 0) {
int status;
wait(&status); // Parent waits for child
printf("Parent process: Child exited with status %d\n",
WEXITSTATUS(status));
} else if (pid == 0) {
printf("Child process: Executing...\n");
exit(5);
}
return 0;
}

Output:
Child process: Executing...
Parent process: Child exited with status 5

6. close()

Definition:
The close() system call closes an open file descriptor.

Program:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
int fd = open("testfile.txt", O_CREAT | O_WRONLY, 0644);
if (fd < 0) {
printf("Error opening file!\n");
return 1;
}
printf("File opened with descriptor %d\n", fd);
close(fd);
printf("File descriptor %d closed.\n", fd);
return 0;
}

Output:
File opened with descriptor 3
File descriptor 3 closed.

7. stat()

Definition:

The stat() function retrieves information about a file, such as its size, permissions, and last
modification time.

Program:
#include <stdio.h>
#include <sys/stat.h>

int main() {
struct stat fileStat;
if (stat("testfile.txt", &fileStat) == 0) {
printf("File Size: %ld bytes\n", fileStat.st_size);
printf("Permissions: %o\n", fileStat.st_mode & 0777);
} else {
printf("Error getting file information.\n");
}
return 0;
}

Expected Output:
File Size: 1024 bytes
Permissions: 644

8. opendir() and readdir()

Definition:

The opendir() function opens a directory, and readdir() reads entries from the directory.

Program:
#include <stdio.h>
#include <dirent.h>

int main() {
DIR *d = opendir("."); // Open current directory
if (d == NULL) {
printf("Error opening directory.\n");
return 1;
}

struct dirent *dir;


printf("Files in current directory:\n");
while ((dir = readdir(d)) != NULL) {
printf("%s\n", dir->d_name);
}

closedir(d);
return 0;
}

Expected Output:
Files in current directory:
.
..
file1.txt
file2.c
a.out
EXPERIMENT NO:3
AIM:Simulate UNIX commands like cp, ls, grep, etc.,

1. Simulating cp (Copy File)

Description:

The cp command copies the contents of one file to another. This program achieves that using
UNIX system calls like open(), read(), and write().

Code:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

#define BUFFER_SIZE 1024

int main(int argc, char *argv[]) {


if (argc != 3) {
printf("Usage: %s <source_file> <destination_file>\n", argv[0]);
return 1;
}

int src_fd, dest_fd;


char buffer[BUFFER_SIZE];
ssize_t bytesRead;

// Open source file in read-only mode


src_fd = open(argv[1], O_RDONLY);
if (src_fd < 0) {
perror("Error opening source file");
return 1;
}

// Open destination file in write mode (create if doesn't exist, truncate


if exists)
dest_fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (dest_fd < 0) {
perror("Error opening destination file");
close(src_fd);
return 1;
}

// Read from source and write to destination


while ((bytesRead = read(src_fd, buffer, BUFFER_SIZE)) > 0) {
write(dest_fd, buffer, bytesRead);
}
// Close file descriptors
close(src_fd);
close(dest_fd);
printf("File copied successfully.\n");

return 0;
}
gcc cp_simulation.c -o cp_sim
./cp_sim source.txt destination.txt

2. Simulating ls (List Directory Contents)

Description:

The ls command lists all files and directories inside a specified directory. This program uses
opendir() and readdir() system calls to read and display the directory contents.

Code:
c
CopyEdit
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

int main(int argc, char *argv[]) {


DIR *dir;
struct dirent *entry;

// Use current directory if no argument is provided


char *dirPath = (argc > 1) ? argv[1] : ".";

// Open directory
dir = opendir(dirPath);
if (dir == NULL) {
perror("Error opening directory");
return 1;
}

// Read directory entries


while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}

// Close directory
closedir(dir);
return 0;
}
gcc ls_simulation.c -o ls_sim
./ls_sim
To list files in a specific directory:

./ls_sim /home/user/Documents

3. Simulating grep (Search for a Pattern in a File)

Description:

The grep command searches for a specific word or phrase inside a file and displays matching
lines. This program achieves that using fgets() and strstr().

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE 1024

int main(int argc, char *argv[]) {


if (argc != 3) {
printf("Usage: %s <pattern> <file>\n", argv[0]);
return 1;
}

FILE *file = fopen(argv[2], "r");


if (file == NULL) {
perror("Error opening file");
return 1;
}

char line[MAX_LINE];
int lineNum = 0;

// Read file line by line


while (fgets(line, MAX_LINE, file) != NULL) {
lineNum++;
if (strstr(line, argv[1]) != NULL) {
printf("Line %d: %s", lineNum, line);
}
}

fclose(file);
return 0;
}

Compile & Run:


gcc grep_simulation.c -o grep_sim
./grep_sim "pattern" filename.txt

This searches for "pattern" inside filename.txt

EXP NO: 4

Simulate the following CPU scheduling algorithms

a) FCFS b) SJF c) Priority d) Round Robin

EXP NO: 5

Simulate Paging Technique of memory management

a)mvt b)mft

EXP NO: 6

Simulate the following file allocation strategies

a) Sequential b) Indexed c) Linked


EXPERIMENT NO: 7

AIM: Simulate the following Page Replacement algorithms


a)FIFO b)LRU c)LFU

a)FIFO:
Aim:
DESCRIPTION:

The simplest page-replacement algorithm is a first-in, first-out (FIFO) algorithm. A FIFO


replacement algorithm associates with each page the time when that page was brought into
memory. When a page must be replaced, the oldest page is chosen.

PROGRAM:

/*C Programto implement FIFO Page Replacement algorithms*/


#include <stdio.h>
int main()
{
int nof, nref, ref[50], frm[10], pf = 0;
int r = 0, flag = 0;
int i, j;
printf("Enter number of frames: ");
scanf("%d", &nof);
printf("Enter number of references: ");
scanf("%d", &nref);
printf("Enter page references: ");
for (i = 0; i < nref; i++)
scanf("%d", &ref[i]);
// Initialize frames with -1 (empty)
for (i = 0; i < nof; i++)
frm[i] = -1;

// Page Replacement Logic


for (i = 0; i < nref; i++)
{
flag = 0;
// Check if page is already in frames
for (j = 0; j < nof; j++)
{
if (ref[i] == frm[j])
{
flag = 1;
break;
}
}
// If page is not found, replace using FIFO
if (flag == 0)
{
pf++;
frm[r] = ref[i];
r = (r + 1) % nof; // FIFO replacement

// Print current frame status


printf("Frames in Memory: ");
for (j = 0; j < nof; j++)
printf("%4d", frm[j]);
printf("\n");
}
}
printf("Number of Page Faults: %d\n", pf);
return 0;
}

OUTPUT:

a) LRU:
Aim: Write a C Program to implement LRU Page Replacement
algorithms
LRU stands for Least Recently Used. As the name suggests, this
algorithm is based on the strategy that whenever a page fault occurs, the
least recently used page will be replaced with a new page. So, the page not
utilized for the longest time in the memory (compared to all other pages)
gets replaced. This strategy is known as LRU paging.
#include <stdio.h>
int main()
{
int i, j, k, min, rs[25], m[10], count[10], n, f, pf = 0, next = 1, pos;
// Input: Length of reference string
printf("Enter the length of reference string: ");
scanf("%d", &n);

// Input: Reference string


printf("Enter the reference string: ");
for (i = 0; i < n; i++)
{
scanf("%d", &rs[i]);
}
// Input: Number of frames
printf("Enter the number of frames: ");
scanf("%d", &f);

// Initialize frames and counters


for (i = 0; i < f; i++) {
count[i] = 0;
m[i] = -1;
}
printf("\nThe Page Replacement process is:\n");

// Process the reference string


for (i = 0; i < n; i++)
{
int flag = 0;

// Check if page is already in memory


for (j = 0; j < f; j++)
{
if (m[j] == rs[i])
{
flag = 1;
count[j] = next; // Update recent usage
next++;
break;
}
}

// If page is not in memory, replace the LRU page


if (flag == 0)
{
if (i <F {
m[i] = rs[i];
count[i] = next;
} else
{
// Find the least recently used page
min = 0;
for (j = 1; j < f; j++)
{
if (count[j] < count[min])
min = j;
}
m[min] = rs[i];
count[min] = next;
}
next++;
pf++; // Increment page fault count

// Display current frames


for (j = 0; j < f; j++)
printf("%d\t", m[j]);
printf("PF No. %d", pf);
printf("\n");
}
}

// Output: Total number of page faults


printf("\nTotal number of page faults using LRU: %d\n", pf);
return 0;
}
C) LFU
Aim: Write a C Program to implement LFU Page Replacement
algorithms
Description:
The least frequently used (LFU) page-replacement algorithm
requires that the page with the smallest count be replaced
Program:
#include <stdio.h>
int main() {
int rs[50], i, j, k, m, f, cntr[20], a[20], min, pf = 0;

// Input: Number of page references


printf("\nEnter number of page references: ");
scanf("%d", &m);
// Input: Reference string
printf("\nEnter the reference string: ");
for (i = 0; i < m; i++) {
scanf("%d", &rs[i]);
}

// Input: Number of frames


printf("\nEnter the available number of frames: ");
scanf("%d", &f);

// Initialize frames and counters


for (i = 0; i < f; i++) {
cntr[i] = 0;
a[i] = -1;
}
printf("\nThe Page Replacement Process is:\n");

for (i = 0; i < m; i++) {


int flag = 0;

// Check if page is already in memory


for (j = 0; j < f; j++) {
if (rs[i] == a[j]) {
cntr[j]++; // Increment counter for frequently used pages
flag = 1;
break;
}
}

// If page is not found in memory, replace the LFU page


if (flag == 0) {
min = 0;
for (k = 1; k < f; k++) {
if (cntr[k] < cntr[min])
min = k;
}
a[min] = rs[i]; // Replace page
cntr[min] = 1; // Reset usage count
pf++; // Increment page fault count
}

// Display current frame status


for (j = 0; j < f; j++) {
printf("%d\t", (a[j] == -1) ? -1 : a[j]);
}

if (flag == 0)
printf("PF No. %d", pf);

printf("\n");
}
// Display total page faults
printf("\nTotal number of page faults: %d\n", pf);

return 0;
}

EXERCISE-8
AIM: Simulate the Banker’s algorithm for Dead Lock Avoidance

DESCRIPTION:

Bankers Algorithm in OS is an algorithm used to manage and allocate


resources in a multi-task environment. It is used to prevent deadlocks and
ensure the system remains in a safe state. The algorithm works by keeping
track of the available resources in the system and allocating them to
processes in a way that ensures that the system will not run out of resources
and enter a deadlock state. The Banker’s Algorithm in OS uses a combination
of resource allocation and deadlock detection to ensure efficient resource
usage and prevent system failures.

Banker’s Algorithm

1. Active:= Running U Blocked;


for k=1…r
New_ request[k]:= Requested_ resources[requesting_ process, k];
2. Simulated_ allocation:= Allocated_ resources;
for k=1…..r //Compute projected allocation state
Simulated_ allocation [requesting _process, k]:= Simulated_ allocation
[requesting _process, k] + New_ request[k];
3. feasible:= true;
for k=1….r // Check whether projected allocation state is feasible
if Total_ resources[k]< Simulated_ total_ alloc [k] then feasible:= false;
4. if feasible= true
then // Check whether projected allocation state is a safe allocation state
while set Active contains a process P1 such that
For all k, Total _resources[k] – Simulated_ total_ alloc[k]>= Max_ need
[l ,k]-Simulated_ allocation[l, k]
Delete Pl from Active;
for k=1…..r
Simulated_ total_ alloc[k]:= Simulated_ total_ alloc[k]- Simulated_
allocation[l, k];
5. If set Active is empty
then // Projected allocation state is a safe allocation state
for k=1….r // Delete the request from pending requests
Requested_ resources[requesting_ process, k]:=0;
for k=1….r // Grant the request
Allocated_ resources[requesting_ process, k]:= Allocated_
resources[requesting_ process, k] + New_ request[k];
Total_ alloc[k]:= Total_ alloc[k] + New_ request[k];

PROGRAM:
/*C Program to implement Dead Lock Avoidance using Banker’s
algorithm*/

#include<stdio.h>

int main() {

int p, c, count = 0, i, j, alc[5][3], max[5][3], need[5][3], safe[5],


available[3], done[5], terminate = 0;

printf("Enter the number of process and resources");

scanf("%d %d", & p, & c);

// p is process and c is diffrent resources


printf("enter allocation of resource of all process %dx%d matrix", p, c);

for (i = 0; i < p; i++) {

for (j = 0; j < c; j++) {

scanf("%d", & alc[i][j]);

printf("enter the max resource process required %dx%d matrix", p, c);

for (i = 0; i < p; i++) {

for (j = 0; j < c; j++) {

scanf("%d", & max[i][j]);

printf("enter the available resource");

for (i = 0; i < c; i++)

scanf("%d", & available[i]);

printf("\n need resources matrix are\n");

for (i = 0; i < p; i++) {


for (j = 0; j < c; j++) {

need[i][j] = max[i][j] - alc[i][j];

printf("%d\t", need[i][j]);

printf("\n");

/* once process execute variable done will stop them for again execution */

for (i = 0; i < p; i++) {

done[i] = 0;
}

while (count < p) {

for (i = 0; i < p; i++) {

if (done[i] == 0) {

for (j = 0; j < c; j++) {

if (need[i][j] > available[j])

break;

//when need matrix is not greater then available matrix then if j==c will
true

if (j == c) {

safe[count] = i;

done[i] = 1;

/* now process get execute release the resources and add them in
available resources */

for (j = 0; j < c; j++) {

available[j] += alc[i][j];

count++;
terminate = 0;

} else {

terminate++;

if (terminate == (p - 1)) {

printf("safe sequence does not exist");

break;
}

if (terminate != (p - 1)) {

printf("\n available resource after completion\n");

for (i = 0; i < c; i++) {

printf("%d\t", available[i]);

printf("\n safe sequence are\n");

for (i = 0; i < p; i++) {

printf("p%d\t", safe[i]);

return 0;

}
EXPERIMENT NO:9

Write a C program to simulate the following contiguous memory allocation techniques

a) Worst-fit b) Best-fit c) First-fit

1. Worst-Fit Algorithm:

The worst-fit algorithm allocates the largest block available that can accommodate the process.
This may leave the largest remaining fragments after allocation, potentially leading to inefficient
memory usage.

#include<stdio.h>
#define max 25

void main() {
int frag[max], b[max], f[max], i, j, nb, nf, temp;
static int bf[max], ff[max];
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d", &nb);
printf("Enter the number of files:");
scanf("%d", &nf);

// Input block sizes


printf("\nEnter the size of the blocks:-\n");
for(i = 1; i <= nb; i++) {
printf("Block %d:", i);
scanf("%d", &b[i]);
}

// Input file sizes


printf("Enter the size of the files :-\n");
for(i = 1; i <= nf; i++) {
printf("File %d:", i);
scanf("%d", &f[i]);
}

// Worst fit allocation


for(i = 1; i <= nf; i++) {
for(j = 1; j <= nb; j++) {
if(bf[j] != 1) { // If the block is not allocated
temp = b[j] - f[i]; // Remaining space after allocation
if(temp >= 0) { // If the block can accommodate the file
ff[i] = j; // Assign block to file
break;
}
}
}
frag[i] = temp; // Fragment left after allocation
bf[ff[i]] = 1; // Mark block as allocated
}

// Display the allocation results


printf("\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragment");
for(i = 1; i <= nf; i++) {
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]],
frag[i]);
}
}

Input:
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

Output:
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3

2. Best-Fit Algorithm:

The best-fit algorithm allocates the smallest available block that can accommodate the process.
This results in minimal unused space but can create very small fragments.

#include<stdio.h>
#define max 25

void main() {
int frag[max], b[max], f[max], i, j, nb, nf, temp, lowest = 10000;
static int bf[max], ff[max];

printf("\nEnter the number of blocks:");


scanf("%d", &nb);
printf("Enter the number of files:");
scanf("%d", &nf);

// Input block sizes


printf("\nEnter the size of the blocks:-\n");
for(i = 1; i <= nb; i++) {
printf("Block %d:", i);
scanf("%d", &b[i]);
}

// Input file sizes


printf("Enter the size of the files :-\n");
for(i = 1; i <= nf; i++) {
printf("File %d:", i);
scanf("%d", &f[i]);
}

// Best fit allocation


for(i = 1; i <= nf; i++) {
for(j = 1; j <= nb; j++) {
if(bf[j] != 1) {
temp = b[j] - f[i]; // Remaining space
if(temp >= 0 && lowest > temp) {
ff[i] = j; // Assign block to file
lowest = temp; // Keep track of smallest fragment
}
}
}
frag[i] = lowest;
bf[ff[i]] = 1; // Mark block as allocated
lowest = 10000; // Reset lowest for next file
}

// Display the allocation results


printf("\nFile No File Size Block No Block Size Fragment");
for(i = 1; i <= nf && ff[i] != 0; i++) {
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]],
frag[i]);
}
}

Input:
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

Output:
File No File Size Block No Block Size Fragment
1 1 2 2 1
2 4 1 5 1

3. First-Fit Algorithm:

The first-fit algorithm allocates the first block that is large enough to fit the process.

#include<stdio.h>
#define max 25

void main() {
int frag[max], b[max], f[max], i, j, nb, nf, temp;
static int bf[max], ff[max];

printf("\n\tMemory Management Scheme - First Fit");


printf("\nEnter the number of blocks:");
scanf("%d", &nb);
printf("Enter the number of files:");
scanf("%d", &nf);

// Input block sizes


printf("\nEnter the size of the blocks:-\n");
for(i = 1; i <= nb; i++) {
printf("Block %d:", i);
scanf("%d", &b[i]);
}

// Input file sizes


printf("Enter the size of the files :-\n");
for(i = 1; i <= nf; i++) {
printf("File %d:", i);
scanf("%d", &f[i]);
}

// First fit allocation


for(i = 1; i <= nf; i++) {
for(j = 1; j <= nb; j++) {
if(bf[j] != 1) { // If the block is not allocated
temp = b[j] - f[i]; // Remaining space
if(temp >= 0) { // If the block can accommodate the file
ff[i] = j; // Assign block to file
break;
}
}
}
frag[i] = temp; // Fragment left after allocation
bf[ff[i]] = 1; // Mark block as allocated
}

// Display the allocation results


printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragment");
for(i = 1; i <= nf; i++) {
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]],
frag[i]);
}
}

Input:
Enter the number of blocks: 3
Enter the number of files: 2

Enter the size of the blocks:-


Block 1: 5
Block 2: 2
Block 3: 7

Enter the size of the files:-


File 1: 1
File 2: 4

Output:

File No File Size Block No Block Size Fragment


1 1 3 7 6
2 4 1 5 1

You might also like