0% found this document useful (0 votes)
24 views38 pages

Ayushi

The document outlines experiments focused on studying hardware and software requirements for various operating systems including Windows 7/8, Windows XP, UNIX, and Linux, detailing their specific hardware needs. It also describes system calls related to process management, file management, and input/output operations, along with examples of CPU scheduling policies such as Shortest Job First, Priority Scheduling, and First-Come, First-Served. Additionally, it provides example programs for implementing these concepts in a programming context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
24 views38 pages

Ayushi

The document outlines experiments focused on studying hardware and software requirements for various operating systems including Windows 7/8, Windows XP, UNIX, and Linux, detailing their specific hardware needs. It also describes system calls related to process management, file management, and input/output operations, along with examples of CPU scheduling policies such as Shortest Job First, Priority Scheduling, and First-Come, First-Served. Additionally, it provides example programs for implementing these concepts in a programming context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Date— 15-04-2025 EXPERIMENT - 1 Objective — Study of Hardware and Software requirements of different Operating Systems (UNIX, LINUX, WINDOWS XP and Windows 7/8) Theory — Hardware requirements: The most common set of requirements defined by any operating system or software application is the physical computer resources, also known as hardware. A hardware requirements list is often accompanied by a hardware compatibility list (HCL), especially in case of operating systems. 1, Windows 7/8 ‘Windows 7 is a major release of the Windows NT operating system developed by Microsoft. It was released to manufacturing on July 22, 2009, and became generally available on October 22, 2009,{9] It is the successor to Windows Vista, released nearly three years earlier. It remained an operating system for use on personal computers, including home and business desktops, laptops, tablet PCs and media centre PCs, and itself was replaced in November 2012 by Windows 8, the name spanning more than three years of the product. ‘Hardware and Software Requirements i. Processor: 1 GHz or faster provessor/ SoC i RAM: | GB for 32-bit OS or 2 GB for 64-bit OS Hard Disk Space: 16 GB for 32-bit OS or 20 GB for 64-bit OS Graphics Card: DirectX9 or later with WDDM 1.0 driver \. Display: 800 X 609 with WDDM Driver 2. Windows XP ‘Windows XP is a version of the Microsoft Windows operating system for personal computers. The letters "XP" stand for eX Perience. Microsoft released Windows XP on October 25, 2001. Windows XP replaced Windows 2000 and Windows ME, which helped bring the NT and 9x versions of Windows together. It was replaced by Windows Vi 2006.4 Windows XP was the second most used computer operating system in the world as late as April 2012. Hardware and Software Requirements i. Processor: 233 MHz or faster processor (300 MHz is recommended) RAM: 64 MB (minimum) 128 MB (recommended) Hard Disk Space: 1.5 GB minimum space iv. CD-ROM or DVD-ROM drive v. Video Adapter and monitor with Super VGA (800 x 600) or higher resolution, vi. Sound Card 3. UNIX OS UNIX is a powerful Operating System initially developed by Ken Thompson, De Ritchie at AT&T Bell laboratories in 1970. It is prevalent among scienti and academic institutions due to its most appreciative features like multi 2301200100073 2(CSE)-A pg Date — 15-04-2025 and many more. In UNIX, the file system is a hierarchical structure of files and directories where users can store and retrieve information using the files. ‘Hardware and Software Requirements i Processor: IBM 604e processor with a clock speed of 375 MHz or faster ii RAM: 1GB Hard Disk Space: /tmp— 1 GB, WAS_HOME — 800 MB, /var — 300 MB, /itim45 - 500 MB 4, LINUX OS Linux isa Unix-like, open source and community-developed operating system (OS) for computers, servers, mainframes, mobile devices and embedded devices. It is supported on almost every major computer platform, including x86, ARM and SPARC, making it one of the most widely supported operating systems. ‘Hardware and Software Requirements i. Processor: 32-bit Intel Compatible processor at 2 GHz or faster ii, | RAM:512 MB ji, Hard Disk Space: 2.5 GB iv. ADVD-ROM Drive 2301200100073 2(CSE)-A pg2 Date — 22-04-2025 EXPERIMENT — 2 Objective —Execute various system calls for Process Management File Management Input/Output System Calls Theory - 1. Process Management Process management uses certain system calls. They are explained below. 1. To create a new process — fork () is used. 2. To run a new program = exee () is used. 3. To make the process to wait = wait () is used. 4. To terminate the process — exit () is used. 5. To find the unique process id — getpid () is used. 6. To find the parent process id — getppid () is used. 7. To bias the currently running process property — nice () is used. 2) Example program for example of fork () [= on | is = Figure: Flow of fork () system call #include #include ‘#include ‘int main () { inti int pid; pid=fork (); if (pid==0) { for (i=0; 1 < 999999; i++) { sleep (2); printf (" from Child process %d\n", i); 2301200100073 2(CSE)-A pg3 Date 22-04-2025 else ( for (i=0; i < 999999; sleep (2); printf (" from Parent process %d\n", i); } i421 J rotum 0; J Output 20) user @node: ~/oslab$. /chp from Parent process 0. from Child process 0 from Parent process 2 from Child process 1 from Parent process 4 from Child process 2 Management ‘There are four system calls for file management, 1. open ():system cal is used to know the file descriptor of user-created files. and write use file descriptor as their Ist parameter so to know the file descriptor open() system call is read ()system call is used to read the content from the file. It can also be used to read the input from the keyboard by specifying the 0 as file descriptor. 3. write (): system call is used to write the content to the file. 4. close ():system call is used to close the opened fil, it tells the operating system that you are done with the file and close the file. ince read used. 2(i). Example program for file management fincludecunistd h> #includecfentl b> fincludecsyv/stat.h> #includecsys/types.h> finclude int main) { int n,fd; char bufi[50}; printf("Enter text to write in the file:\n"); n= read(0, buff, 50); fd~open('"file",O_CREAT | O_RDWR, 0777); write(fd. buff. n): write(1, buff, n); int close(int fd); retum 0; 2301200100073 2(CSE)-A ps4 Date — 22-04-2025 Output 2¢) Enter text to write in the file: Hello world, welcome @ IncludeHelp Hello world, welcome @ IncludeHelp 3. Input/Output System Calls Basically there are total 5 types of I/O system calls: © Create: Used to Create a new empty file. © open: Used to Open the file for reading, writing or both. ‘© close: Tells the operating system you are done with a file descriptor and Close the file which pointed by fa. ‘+ read: From the file indicated by the file descriptor fd, the read() function reads ent bytes of input into the memory area indicated by buf. A successful read() updates the access time for the file. write: Writes cnt bytes from buf to the file or socket associated with fd. cnt should not be greater than INT_MAX (defined in the limits.h header file). If cnt is zero, write() simply returns 0 without attempting any other action. 2Gii) Example program for Input/output System Calls, main(){ read(0, &a. 3): ina; write(1, &i, 3); write(1, "\a", 1); J Output 2(iii) ansh @node:~/oslab$ fio EEBBRY 2301200100073 2(CSE)-A pgs Date — 20-04-2025 EXPERIMENT - 3 Objective — Implement CPU Scheduling Policies i, SIF ji, Priority FCFS iv. Multi-Level Queue Algorithm: Step 1. Sort all the process according to the arrival time. Step 2. Then select that process which has minimum arrival time and minimum Burst time. Step 3. After completion of process make a pool of process which after till the completion of previous process and select that process among the pool which is having minimum Burst time. Example: Sorting the process according to brust time. (Array sorting flowchart can be used for logic understanding) Shortest Job First Normal SE 1 The Gante Chart for SIF (Noemal is * Average waking ime = (0+3+7)/3= 3.33 (i). Example program for SJF scheduling implementation fincludecstdio.h> struct process { int id; int brust; i typedef struct process proc; int main() { int n; printf("enter the number of process: "); scanf("%d", &n); Proc p[n], temp; intij: forGi=O;icn;it+) { pliJ-id=i; printf("enter the brust time of process P 9d :", i); scanf("%d", &pfi]-brust); J for(i=O;icn-1:i++) ( for(j=it1:jcn;j++) { if(plj]-brust < pli]. brust){ temp.id = plj].ic; 2301200100073 2(CSE)-A pg.6 Date — 20-04-2025 emp id; plil.brust = temp.brust; } J int wt=0; ‘int twt=0; printf("\n scheduling information \n"); for(i=O;icnsi++) { tut = twiswt; printf(" process id: %d \t wating time: %d \n" p[i].id, wt ); wt=wt+p[i].brust; J print{("\n average waiting time: %1.2f:", (float)owi/n)); retum 0; } Input: Program 3(i): Process Brust Time PO 5 Pi 3 P2 6 P3 4 Output: scheduling information process id: 1 wating time: 0 Process id: 3 wating time: 3 process id: 0 wating time: 7 process id: 2 wating time: 12 average waiting time: 5.50 2. Priority Scheduling Algorithm: Step 1. First input the processes with their arrival time, burst time and priority. Step 2. Sort the processes, according to arrival time if two process arrival times is same then sort according process priority if two process priority are same then sort according to process number. Step 3. Now simply apply FCFS algorithm. Example : Sorting the process according to priority. (Array sorting flowchart can be used {for logic understanding) 2301200100073 2(CSE)-A pg7 Date — 20-04-2025 + Average wating time = (640416 +18 4/5= 82 (ii). Example program for Priority scheduling implementation #include struct process { int id: int brust; int pr, typedef struct process proc; ‘int main() { int n; printf("enter the number of proces scanf("%d", &n); proc p[n], temp; inti, for(i=O:icn:i++) { plilid=i: printf("enter the brust time of process P %d :",i); scani("%d", &pfi].brust); printf("enter the priority of process P %d :", i): scani("%d", &pli].pr): } for(i=Osicn-lsi++) { for(j=it l:j typedef struct process proc: 2301200100073 2(CSE)-A Date — 20-04-2025 int main() { int n; printf("enter the number of process: "): seani("%d", &n); proc p[n], temp: intij; for(i=O;icnsit+) ( pli) .id=i: printf("enter the brust time of process P %d :" scan{("%d", &pfi]-brust); printf("enter the arival time of process P %d :", i scani("%d", &pfi].at); J for(i=O;icn-1:i++) { forG=it lj #includecstdlib.h> typedef struct process { int num; int arrive; ‘int brust, int pt; int f int cpu; ‘int wait; } proces typedef struct queue { process p[10]; int front; int rear; } queue: Void insert(queue *4,process t) { > plq>rear]=t; q->reart+; } Void pstack(queue *que) { inti; forGi=Osic3:i++) { printf("\n queue %dis \n",i+1); printf("Process\tarive\tbrusi\t type\t 1/O\t cpu \swait\n"); for(j=0;j que[k].plj+1].artive){ temp=Squelk}.plj}s 2301200100073 2(CSE)-A pgit Date — 20-04-2025 que[k]-p{j}=que(k].pli+1]; quell] plj+1}=temp:; wh void pque(queue *que){ int c=0,cp=0; int w=0; int j=0,k=0,1=0,t=0,i; process “temp; ‘int max=0; for(i=O:ic3:i++) { ‘max=max+-que[i].rear; wel tl cout c=c+-quelO} pj}. brust jes ep=cs continue; } else if(que[).pIk].amive < cp && k < quet 1].rear ){ que(1}.pik].cpu=c; quef].p{k].wait=c-quef1 ].pfk] arrive; if(que{ 1).p[k].wait < 1) que(1) pik].wait=0; c=c+que[1].p[k].brust; ket p=; continue; } else if(quel2}.pll]-arrive < ep && I< que[2]-rear){ uel if(que[2) pll-wait <1) quel], c=c#+quef2} pl}. brust; les printi(“enter the number of process 2301200100073 2(CSE)-A pg.12 Date — 20-04-2025 scani("%d",&n), temp.num=i+1; temp.cpu=0; temp.wait=0; printf("\n enter the ariive time of process %d +1); scanf("%d'" &ctemp.arrive); printi("\n enter the brust time of process %d =",i+ 1); scanf("%d" &temp brust): printf("\n enter the type of(1-bac! i+1); scanf("%d" &temp printi("\n enter the feedback of process(0-for normal, 1-1/0) %d =",i+1); scanf("%d" &temp.1); if(temp.pt>=2 && temp.f==1) insert(&queltemp.pt-2].emp); else if(temp.f==0) inser equetemp pomp): insert(&que[temp.pt-1].temp); } pstack(que); fefs_sort(que); printi("\n\nafter sorting of process list is \n\n"); pstack(que); Paque(que); printf("\n\nafter processing epu and wait is \n\n"); pstack(que): retum 0; J Input: Program 3(iv): Process | Arival Time) Brust Time | Process Type | 1/0 ro [2 1 0 rm (2 5 a 0 pd 3 a 0 Pa 1 3 [2 0 PS o 4 2 o P62 ‘4 [2 0 wd 3 3 0 PB 3 4 3 0 Po 2 6 3 o Output: queue Lis Process. arive brust- type VO cpu wait 1 0 2 10 «0 0 2 2 5 10 0 0 3 1 3 1 0 0 oO 2301200100073 2(CSE)-A pg.13 Date — 20-04-2025 queue 2 is Process ative brust type VO cpu wait 4 1 3020 0 0 5 0 4 2 0 0 0 6 2 4 20 0 0 queue 3 is Process arive brust type VO cpu wait 1 1 3.3 0 0 0 8 3 4 3 0 0 0 9 2 6 3 0 0 0 after sorting of process list is queue 1 is Process ative brust type VO cpu wait 1 0 2 10 0 0 3 1 3. 10 0 0 3 1 3 10 0 0 queue 2 is Process arive —brust type VO cpu wait 5 0 4 20 0 0 5 0 4 20 0 0 6 2 4 20 0 0 ‘queue 3 is Process arive —brust type VO cpu wait 1 1 3.3 0 0 0 9 2 6 3 0 0 0 9 2 6 3 0 0 0 after processing cpu and wait is queue 1 is Process ative brust type VO cpu wait 1 0 2 10 0 0 3 1 3 10 2 1 3 1 3 10 5 4 queue 2 is Process ative brust type VO cpu wait 5 0 4 2 0 8 8 5 0 4 2 0 2 12 6 2 4 2 0 6 14 queue 3 is Process ative brust- type VO cpu wait 7 1 3. 3 0 2% 19 9 2 6 3 0 23 2 9 2 6 3 0 22% 27 2301200100073 2(CSE)- A pg. 14 Date - 06-05-2025 EXPERIMENT - 4 ‘Objective - Implement file storage allocation technique: i, Contiguous(using array) Linked —list(using linked-list) Indirect allocation (indexing) Theory — 1. Contiguous Allocation About Contiguous allocation technique: In this scheme, each file occupies a contiguous set of blocks on the disk. For example, if a file requires 1n blocks and is given a block b as the starting location, then the blocks assigned to the file will be: b, b+, bi2,......btm-1. This means that given the starting block address and the length of the file (in terms of blocks required), we can determine the blocks occupied by the file. The directory entry fora file with contiguous allocation contains Address of starting block Length of the allocated portion. 4G). Example program for Contiguous(using array)file storage allocation technique #include struct filep { int id; int start; int count; k typedef struct filep files; int mainQ) { int disk[ 100]; for(i=O3i <3:i++) fil.id=i, forti=Oi<3ii+4) { flag=0; for(i=0}<100;j+4){ if(disk{j] == -1) { for(k=jk< j+{[i].count && disk[k] == -1:k++) { flagt++; printf("\n flag for file %d : %d\n", i, flag); } if (flag == f[ij.count) { for(k=jck< j+ff 2301200100073 2(CSE)- A pg. 15 Date - 06-05-2025 J=)+li].count; break; } else { iejefla: flag=0; N iG==99 && flag == 0) printf("\n disk is full \n"); n printf("\n here is the disk allocation details \n"); for(i=0;i<100;i++) rintf("%d", disk{i)); return 0; } Input: Program 4(i): Disk Size = 100 (Block (all of equal size)) File ID Block_Count Filed 3 File 1 3 File2 2 Output: here is the disk allocation detail OOOOO1L 122-1 1-2-1 1-1-1 1-1-1 1-1-1 2-1-1 1-1-1 -1-1- cece ee eel CeCe cece ccc cc cee cee ce ccocrnnnnnt D-DD -1 1-1 1-1-1 1-1 1-11-1111 2. Linked List About Linked List Allocation technique: In this scheme, each file is a linked list of disk blocks which need not be contiguous. The disk blocks can be scattered anywhere on the disk. The directory entry contains a pointer to the starting and the ending file block. Each block contains a pointer to the next block occupied by the file. The file ‘jeop’ in following image shows how the blocks are randomly distributed. The last block (25) contains -1 indicating a null pointer and does not point to any other block. Figure: Linked List file allocation technique 2301200100073 2(CSE)- A pg. 16 Date - 06-05-2025 Example program for file storage allocation technique (Linked List Allocation) #include #include struct file{ int id; int block; struct file *next_block; K typedef struct file f; int mainQ{ £file1, “temp, *temp2; int i=1,j, count; fox=0 jid=i; temp->bloct temp->next_block=NULL; filei=temp; printf("%dl\", else{ temp=filel; while (temp->next_block != NULL) temp=temp->next_block; temp2=(F*)malloc(sizeot(f)); temp2->id: temp2->block=j temp2->next_block=NULL: temp->next_block = temp2; printf("%6dl\t", 3 } J printf("\n Here is the disk allocation for file : \n"): temp=filel; while(temp!=NULL){ printf("file id: %d\t block number: %d\t block address %d\n", temp->id, temp- >block,(int)temp); temp=temp->next_block; } return 0;} Input: File ID Block_Count Filet 5 Output: Here is the disk allocation for file : file id: 1 block number: 0 block address 38287408 2301200100073 2(CSE)- A pg. 17 Date - 06-05-2025 block number: 1 block address 38287440 block number:2 block address 38287472 block number:3 block address 38287504 block address 38287536 block number:5 —_ block address 38287568 3. Indirect Allocation About Indirect allocation (indexing) technique: In this scheme, a special block known as the Index block contains the pointers to all the blocks occupied by a file. Each file has its own index block. The ith entry in the index block contains the disk address of the ith file block. The directory entry contains the address of the index block as shown in the image: Directory fte_index block feo 30 Figure: Indirect (index) file allocation technique Example program for file storage allocation technique (Indirect (index)) #include #include struct file{ int id; int block; struct file *next_block; h typedef struct file f int main(){ f *files[3}, “temp, *temp2; int count, i,j, id; fori=Oi<3;i+4){ printf("enter the number of blocks for file : %d", i); scanf("%d", &count): for(i=0:jid=i;, temp->blocl temp->next_block=NULL; else{ temp=filestil; while (temp->next_block != NULL) 2301200100073 2(CSE)- A pg. 18 Date - 06-05-2025 temp=temp->next_block; temp2=(f*)malloc(sizeof(f)); temp2->id=i; temp2->block=} temp2->next_block=NULL; temp->next_block = temp2; printf("%d\t", i); My temp=filesfid]; while(temp!=NULL){ printf("file id: %d\t block number: %d\t block address %d\n", temp->id, temp- >block,(int)temp); temp=temp->next_block; } return 0: } Input: Program 4(ii): File ID Block_Count File 0 3 File 1 q File2 6 Output: disk allocation using index as file id file id: 0 block address 35997744 file id: 0 block address 35997776 file id: 0 block address 3599780 file id: 0 block address 35997840, file id: 0 block address 35997872 file id: 1 block address 35997904 file id: 1 block address 35997936 file id: block address 35997968 file id: 1 block address 35998000, file id: 2 block address 35998032 file id: 2 block address 35998064 file id: 2 block address 35998096 file id: 2 block address 35998128 file id: 2 block address 35998160, file id: 2 block address 35998192 2301200100073 2(CSE)- A pg. 19 Date — 13-05-2025 EXPERIMENT - 5 Objective - Implementation of contiguous allocation techniques: i Worst-Fit 1. Worst Fit 1 Fit Allocate the process to the partition which is the largest sufficient among the freely available available in the main memory. Algorithm: Step 1. Input the total number of blocks and their si Step 2. Input the total number of processes and thei Step 3. For each process in list Find free block having max size and greater than process size Allocate block to process 2. Example program for implementation of contiguous allocation techniques: Worst-Fit #include int fragment; Iprocess; int main({ int ab, np, i, j; int disk_index=0; printf(" Total disk size is 50 \n printf(" enter numebr of blocks: "); scanf("%d", &ab); struct blocks bls[nb), temp; forGi=O:icnbsit+) bisfil.bid=i: printf("enter the size of block %d", i); scanf("%d", &blsfi).size); bls[i.index=disk_index; disk_index=disk_index+bls[i].size; } printf(" enter numebr of process: "); scanf("%d" Senp); 2301200100073 2(CSE)- A pg. 20 struct processs ps{np]; fori=O;i bls[i] size) temp bid = bls{j].bid; bls{i].index = temp.index; wy forli=O;i= nb || bls{i].size < psfi].size) printf("\n no block else psfiLb=blsfi]; } printf(" \n now process block allocation list is \n"); fordi=O:i #include int disk{20]; int flag; struct blocks b; int fragment; }process; int main({ int nb, np, i, js int disk_index=0; printf(" Total disk size is 20 \n"); printf(" enter numebr of blocks: scanf("%d", &nb); struct blocks bls{nb]; for(i=Oricnb:i++){ bis{i].bid=i; printf("enter the size of block %d -anf("%d", &blsfi).size); blsfi].index=disk_index; disk_index=disk_index+bls[i] size; } printf(" enter numebr of process: scanf("Sd".&np): struct processs ps{np]; for(i=O:i process _size Allocate block to process 2301200100073 2(CSE)- A pg. 23 Date — 13-05-2025 Example program for implementation of contiguous allocation techniques: First-Fit Hinclude #include int disk{20); struct blocks { int bi int size; int index; int status; block; struct processs| int pid; int int flag: struct blocks b; int fragment; }process; int main()( printf(" Total disk size is 50 \n"); printf(" enter numebr of blocks: "); seanf("%d", &ab); struct blocks bls{nb], temp; forti=O:i psfi).size && bls{j).status ==-1) { psfil-b=blsfj]s bls{jl.status = 1; break; my printf(" \n now process block allocation list is \n"); for(i=Osicnp:i++){ 2301200100073 2(CSE)- A pg. 24 Date — 13-05-2025 Input: Program S(ii): Block ID Block_size Block 0 5 Block 1 4 Block 2 8 Block 3) 3 Process ID Process_size Process 0 3 Process 1 2 Process 2 4 Output: now process block allocation list is process id: 0 process size 4 block id 0 free space 1 process id: 1 process size 2 block id 1 free space 2 process id: 2. process size 3. block id 2 free space 5 2301200100073 2(CSE)-A pg. 25 Date - EXPERIMENT - 6 ‘Objective - Calculation of Internal and External fragmentation i, Free space list of blocks from system ii, List process file from the system Theory — 1. Fres space list of blocks from system External Fragmentation: External fragmentation happens when there’s a sufficient quantity of area within the memory to satisfy the memory request of a method. However, the process’s memory request cannot be fulfilled because the memory offered is during a non-contiguous manner. Either you apply first-fit or best-fit memory allocation strategy it’ll cause external fragmentation. Process 07 + needs 50KB fiat “Ke memory spi Fragment |] 10KB Fr nt i$ 5KB Figure. External Fragmentation in System Example program for Free space list of blocks from system #include #include int disk{20]; struct blocks { int bi int size; ‘int index; int status; Yblock; struct processs| int pid; int size; int flag: struct blocks b: int fragment; Iprocess; int main() int nb, np, i, js int di index=0; printf(" Total disk size is 50 \n"); printf(" enter numebr of blocks: ");, scanf("%d", &ab); struct blocks bls[nb], temp; for(i=Oxi Hincludecsidlib.h> int disk{20]; struct blocks { int bi int size; int index; int status; block; struct processs| int pid; int size; int flag: struct blocks b; int fragment; }process; int mainQ{ int nb, np, i. js int disk_index=0; printf(" Total disk size is 50 \n"); printf(" enter numebr of blocks: "); scanf("%6d", &ab); struct blocks bls[nb], temp; forti=Oicnbiit+){ blsfi).bid=i; printf("enter the size of block %d scanf("%d", &blsfi].size); blsfi].index=disk_index; disk_index=disk_index+bls[i] size: blsfi}.status = -1; 2301200100073 2(CSE)- A PAGE-22 Date - } printf(” enter numebr of process: "); scanf("%d",&np); ‘struct processs ps[np]; for(i=O:i psfi psfil-b=bls{j]; blsfj.status = 1: break; my printf(” \n now process block allocation list is \n"); int t_free=0; forti=O:icnp:i+4){ printf(" process id: %d process size %d_ block id %d free space %d\n", psfi} pid, psfil-size, psfi}.b.bid, ps[i] t_free = t_free + (ps[i).b. size-psfi].size); } printf(" \n Total internal fragmentation space is: %d \n", t_free); return 0; Block ID Block_size Block 0 Block Block 2 Block 3 19) c0] +f Process ID Process_size Process 0 Process 1 Process 2 js] rofus Output: now process block allocation list is, Total internal fragmentation space is: 8 2301200100073 2(CSE)- A PAGE-23 Date. - EXPERIMENT -7 Objective - Implementation of compaction for the continually changing memory layout and calculate total movement of data Theory — Memory compaction The longstanding memory fragmentation problem has been covered many times in these pages. In short: as the system runs, pages tend to be scattered between users, making it hard to find groups of physically-contiguous pages when they are needed. Much work has gone into avoiding the need for higher-order (multi-page) memory allocations whenever possible, with the result that most kernel functionality is not hurt by page fragmentation. But there arc still situations where higher-order allocations are needed; code which needs such allocations can fail on a fragmented system. Example: Figure: Memory status (where red part are the occupied block and white cells free memory) Movable Figure: Move the free space one side and occupied nH Ll space on another side Figure: Memory after compaction Example program for Implementation of compaction for the continually changing memory layout and calculate total movement of data #include #include int disk{20}; struct blocks{ int bid; int size; int index: int status; block; }process; int mainQ{ int nb, np. i. j: int disk_index=0; 2301200100073 2(CSE)- A pg. 30 Date -05-2025 printf(" Total disk size is 50 \n"); printf(” enter numebr of blocks: "); for(i=O;icnb;i++) blsfi).bid=i; intf("enter the sizeof block Yd " i) } printf(” enter numebr of process: "); scanf("%d" Senp); struct process ps[np]: forGi=O:i psfi)-size && bisfj].status psfil.b=blsfj]; bls{j}-status = 1; break; Wy printf(" \n now process block allocation list is \n"); for(i=Osi

You might also like