Os Lab Manual Final PDF
Os Lab Manual Final PDF
Date :
AIM:
PROCEDURE:
1. Insert the installation DVD into the optical bay or the bootable USB disk into your computer.
Note: if using a desktop case try to insert the USB drive into one of the rear ports. Front-panel USB
connectors are more convenient to use but can cause issues during the install process.
2. Press the F8 key multiple times while the computer starts to call the Boot Manager menu.
3. Use the arrow keys to select the drive unit that contains the Windows 11 installer. Some drives may show
up twice. If so I recommend you chose the version that’s named EFI or UEFI. This is the best way to install
Windows 11 and it’s a hassle to switch to UEFI after installing the OS in legacy BIOS mode (learn about
UEFI vs BIOS).
4. Next, a message to Press any key to boot from the CD or DVD… appears. Doing so will start the actual
Windows 11 installation process and the new Windows 11 flat logo will show up.
5. First step is to choose to Install now. On this screen, you’ll also see an option to Repair your computer.
You’ll ignore it for this guide.
6. The installer will ask now to choose the language of the interface, the time and currency format, and
the keyboard layout. These can be mixed and matched to your preference, and don’t need to reflect reality.
Changing them at a later date is possible without reinstalling Windows 11.
7. At the next step you’ll be asked to enter the Windows 11 product key. This step can be skipped for now,
but you’ll have to eventually activate Windows 11 to get all the features. Be careful and enter the correct
code provided with your license. The serial key is made up of 25 characters (5 groups of 5 letters and
numbers each).
8. Now it’s time to select the Windows edition you want to install. Your selection must match the
product key entered earlier or else Windows won’t activate.
9. To proceed you next need to agree to the licensing terms (EULA).
10. Next select the installation type. There are two options: Upgrade an existing installation of Windows
(version 7, 8, or 10) or Custom.
Upgrade doesn’t work anyway from this installer. You need to boot into Windows, plug the installer kit CD
or USB disk, then start Setup.exe from File Manager. I don’t know why Microsoft still shows the Upgrade
option here.
If you don’t have a previous Windows version installed just select the latter option.
11. At this step you’ll see all available disks detected in your computer. Let the installer know the disk
where Windows 11 files will be copied. You can choose to partition the existing disk into smaller virtual
disks (recommended for bigger disks). If you only have one unformatted disk just select it and hit Next. The
installer will create all the needed partitions for you.
Expect an advanced setup guide for this install step so check back to BinaryFork. I’ll make sure to link the
guide back here. I think it is a must-know if you’re reinstalling Windows, installing it on a multi-disk
computer, and especially if you want to dual-boot other operating systems next to Windows 11.
12. The installer will now start to copy the required files from the install medium to their final destination.
A reboot will definitely happen at this point.
13. If this is a deja-vu, don’t worry, because you’re asked again to select the geographical region and
keyboard layout. They can differ from the original choice and will override the settings from step 6. You
can optionally add more keyboard layouts (hint: use WIN + Shift to switch between them while using
Windows).
14. All previous screens are almost identical to the Windows 10 installer. Now we’re getting the first newly
designed screen: name your PC. I suggest you enter a computer name that’s recognizable and easy to
remember.
15. The installer will now check for any updates and download them before proceeding. Let it do its thing.
16. At this next step you’ll select the predefined device usage scenario: for Personal use or Organization,
in which case your system administrator will enforce some settings for you after you login into your
company network. We’ll be using the Personal option for this guide.
17. Now it’s time to create the administrator account for this PC. Microsoft still tries to make you sign in
with your outlook.com account, but I suggest you stick to an offline account for privacy reasons.
18. To ensure you can recover your files if you don’t remember your password you’ll need to provide
answers to one of the 3 security questions set up at this step.
18a. If you sign in with a Microsoft account, you will be asked to Create a PIN to log in quicker to your
computer, instead of using the complex Microsoft password.
You can complete a more secure PIN if you wish, but by default, you’re only required to add numbers, not
letters and symbols.
19. If this is not your first Windows device and you had set up settings sync in the past you can choose to
restore settings from another machine (it can also be the same machine if you’re reinstalling Windows).
By default, Microsoft shows the last device that was synced, but you can click on the Restore from another
device link and you will see a list of all devices associated with your Microsoft account.
For this guide, we’ll just select Set up as new device.
20. Privacy settings are next. By habit, I disable everything that’s possible without hampering the use of
Windows. Expect some telemetry data to still be sent to Microsoft, but I’m working on an article about how
to disable pretty much everything that affects privacy in Windows 11.
21. This is a new step, which will ask you to select the basic types of activities you’ll be doing with your
new machine. Options include Entertainment, Gaming, School, Creativity, Business, and Family.
Based on your selection Windows will personalize tips, ads, and recommendations. You can just press
Skip, as all these options can be changed later in the Settings app in the Personalization > Device Usage
section. 22. You’ll now be asked to set up an automatic backup with OneDrive. It’s part of the Windows
settings sync, which we’ve talked about extensively here. You can just click on the Only save files to this
PC link and continue.
23. Now you can set up your Microsoft 365 Family plan 1 monthly trial for Office + 1TB OneDrive cloud
space. If you don’t need it click Decline. If you already have an active subscription you can click on the I
have a product key to link this device
24. Another promo, this time for Xbox Game Pass. It’s a pretty good deal if you’re a serious gamer. You can
press Skip for now to proceed further.
25. After a few moments and a couple of different screens you’ll be greeted with the new Windows 11
desktop for the first time. Don’t worry, the start menu is supposed to be centered!
RESULT:
Date :
AIM:
To study the basic commands in unix.
COMMON UNIX COMMANDS:
Command Action
cd
<directory> Change directories
cp
<file><file2> Copy the contents of file into file2
List file information in long format, sorted by time with newest files or newly
ls -lt changed files
appearing first
rmdir
<directory> Remove directory
COMMAND EXAMPLES:
Create
Directory (mkdir)
Type
mkdir<directorynam e>
Create a mkdir playground Once you've made the directory,
Directory and press Enter. use the ls command to verify.
To make a new directory
called playground.
Copy Files
(cp)
Type
To copy a cp<file><file.copy>
file in and cp resume resume.copy
the same press Enter.
directory. To make a copy of a file
named
"resume" in the same
directory.
Type
To copy a cp<file><directory>
file and cp resume private
into
another press Enter.
directory.
Remove a
File (rm)
Remove a
Directory (rmdir)
RESULT:
The unix commands are executed successfully in the terminal and outputs are verified.
Ex no : 2.b) SHELL PROGRAMMING
Date :
AIM:
ALGORITHM:
PROGRAM CODING:
num="1 2 3 4 5 6 7 8 "
for n in $num
do
q=`expr $n % 2`
if [ $q -eq 0 ]
then
echo "even no"
continue
fi
echo "odd no"
done
OUTPUT:
RESULT:
Thus the shell program to check number is executed and verified successfully.
ii) MULTIPLICATION TABLE USING SHELL PROGRAM
AIM:
To print the multiplication table using shell program.
ALGORITHM :
1. Read n
2. Check the for loop
3. Calculate and print the result
4. Repeat 2 until condition becomes false.
PROGRAM CODING:
OUTPUT:
RESULT:
Thus the program to print the multiplication table using shell program is executed and verified successfully.
Ex no : 3 PROCESS MANAGEMENT USING SYSTEM CALLS
Date :
AIM :
To execute fork() system call.
ALGORITHM :
4. Otherwise if pid is equal to 0 print output as null else print the process id.
PROGRAM CODING :
#include<stdio.h> #include<stdlib.h>
#include<unistd.h> void main(int
argc,char* arg[]) {
int pid;
pid=fork();
if(pid<0){
printf("fork failed");
exit(1);
} else if(pid==0) { execlp("whoami
","is",NULL); exit(0); } else{ printf("\n
process id is - %d \n",getpid());
wait(NULL); exit(0); }
}
OUTPUT:
RESULT:
AIM :
To execute the getpid() and getppid() system calls
ALGORITHM :
PROGRAM CODING:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main(){
int pid;
pid=fork();
if(pid==-1){
perror("fork failed");
exit(0);
}
if(pid==0)
{
printf("\n child process is under execution");
printf("\n process id of the child process is %d",getpid());
printf("\n process id of the parent process is %d",getppid());
}
else{
printf("\n parent process is under execution");
printf("\n process id of the parent process is %d",getpid());
printf("\n process id of the child process in parent is %d",pid);
printf("\n process id of the parent of parent is %d",getppid());
}
return(0);
}
OUTPUT:
RESULT:
Thus the getpid() and getppid() system calls are executed and verified successfully
iii) PROGRAM USING SYSTEM CALLS wait( ) & exit( )
AIM :
To execute the wait() and exit() system calls
ALGORITHM :
PROGRAM CODING:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
void main(){
int i,pid;
pid =fork();
if(pid==-1){
perror("fork failed");
exit(0);
}
else if(pid==0){
printf("\n child process starts");
for(i=0;i<5;i++){
printf("\n child process %d is called ",i);
}
printf("\n child process ends");
}
else{
wait(0);
printf("\n parent process ends");
exit(0);
}
}
OUTPUT:
RESULT:
Thus the wait() and exit() system calls are executed and verified successfully
Ex no : 4 WRITE C PROGRAMS TO IMPLEMENT THE VARIOUS CPU SCHEDULING
Date : ALGORITHMS
AIM:
To implement FCFS CPU scheduling algorithm
ALGORITHM:
#include<stdio.h>
#include<conio.h>
int p[30],bt[30],tot_tat=0,wt[30],n,tot_wt=0,tat[30],fcfs_wt=0,fcfs_tat=0;
float awt,avg_tat,avg_wt;
void main(){
int i;
printf("\n enter the no of processors\n");
scanf("%d",&n);
printf("\n enter burst time for each process\n");
for(i=0;i<n;i++){
scanf("%d",&bt[i]);
p[i]=i;
}
printf("\n fcfs algorithm \n");
wt_tat(&fcfs_tat,&fcfs_wt);
printf("\n \n total turn around time:%d",fcfs_tat);
printf("\n average turn around time:%d",fcfs_tat/n);
printf("\n total waiting time:%d",fcfs_wt);
printf("\n total avg waiting time :%d",fcfs_wt/n);
}
int wt_tat(int *a,int *b){
int i;
for(i=0;i<n;i++){
if(i==0)
tat[i]=bt[i];
else
tat[i]=tat[i-1]+bt[i];
tot_tat=tot_tat+tat[i];
}
*a=tot_tat;
wt[0]=0;
for(i=1;i<n;i++){
wt[i]=wt[i-1]+bt[i-1];
tot_wt=tot_wt+wt[i];
}
*b=tot_wt;
printf("\n process \t\t burst time \t+turn around time\t waiting time");
for(i=0;i<n;i++)
printf("\n process[%d]\t\t%d\t%d\t\t%d",p[i],bt[i],tat[i],wt[i]);
return 0;
}
RESULT:
Thus the FCFS CPU scheduling algorithm is executed and verified successfully.
ii) SJF (SHORTEST JOB FIRST) CPU SCHEDULING ALGORITHM
AIM:
To implement the SJF CPU scheduling algorithm
ALGORITHM:
#include<stdio.h>
int p[30],bt[30],tot_tat=0,wt[30],n,tot_wt=0,tat[30],sjf_wt=0,sjf_tat=0;
float avt,avg_tat,avg_wt;
void main(){
int i;
printf("\n enterthe no of proccessors\n");
scanf("%d",&n);
printf("\n enter the burst time for each processors\n");
for(i=0;i<n;i++){
scanf("%d",&bt[i]);
p[i]=i;
}
sort();
wt_tat(&sjf_tat,&sjf_wt);
printf("\n\n total turn around time:%d",sjf_tat);
printf("\n average turn ariund time :%d",sjf_tat/n);
printf("\n tatol waiting time:%d",sjf_wt);
printf("\n total avg waiting time:%d",sjf_wt/n);
}
int sort()
{
int t,i,j;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++){
if(bt[i]>bt[j]){
swap(&bt[j],&bt[i]);
swap(&p[j],&p[i]);
}
}
}
return 0;
}
int swap(int *a,int *b){
int t;
t=*a;
*a=*b;
*b=t;
return 0;
}
int wt_tat(int *a,int *b){
int i;
for(i=0;i<n;i++){
if(i==0)
tat[i]=bt[i];
else
tat[i]=tat[i-1]+bt[i];
tot_tat=tot_tat+tat[i];
}
*a=tot_tat;
wt[0]=0;
for(i=1;i<n;i++){
wt[i]=wt[i-1]+bt[i-1];
tot_wt=tot_wt+wt[i];
}
*b=tot_wt;
printf("\n process\t\t burst time \t turn around time\t waiting time");
for(i=0;i<n;i++)
printf("\n process[%d]\t\t %d\t \t %d\t \t %d",p[i]+1,bt[i],tat[i],wt[i]);
}
RESULT:
Thus the SJF CPU scheduling algorithm is executed and verified successfully.
iii) PRIORITY CPU SCHEDULING ALGORITHM
AIM:
To implement priority CPU scheduling algorithm
ALGORITHM:
RESULT:
Thus the SJF CPU scheduling algorithm is executed and verified successfully.
iv) ROUND ROBIN CPU SCHEDULING ALGORITHM
AIM:
To implement ROUND ROBIN CPU scheduling algorithm
ALGORITHM:
RESULT:
Thus the ROUND ROBIN CPU scheduling algorithm is executed and verified successfully.
Ex no : 5 ILLUSTRATE THE INTER PROCESS COMMUNICATION STRATEGY
Date :
i) SHARED MEMORY:
AIM:
To illustrate the inter process communication strategy
ALGORITHM:
PROGRAM:
Shared1.c:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/shm.h>
#include<string.h>
int main(){
int i;
void *shared_memory;
char buff[100];
int shmid;
shmid=shmget((key_t)2345,1024,0666|IPC_CREAT);
printf("key of shared memory is %d\n ",shmid);
shared_memory=shmat(shmid,NULL,0);
printf("process attached at %p \n",shared_memory);
printf("\n enter the some data to write to shared memory\n");
read(0,buff,100);
strcpy(shared_memory,buff);
printf("you wrote:%s\n",(char *)shared_memory);
}
Shared2.c
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/shm.h>
#include<string.h>
int main(){
int i;
void *shared_memory;
char buff[100];
int shmid;
shmid=shmget((key_t)2345,1024,0666);
printf("key of shared memory is %\n",shmid);
shared_memory=shmat(shmid,NULL,0);
printf("process attached at %p \n",shared_memory);
printf("data read from shared memory is :%s /n",(char *)shared_memory);
}
OUTPUT:
RESULT:
Thus the inter process communication using c program is executed and output is verified.
Ex no : 6 IMPLEMENT MUTUAL EXCLUSION BY SEMAPHORES
Date :
AIM:
To implement mututal exclusion by semaphores
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
#include<unistd.h>
sem_t mutex;
void* thread(void* arg){
sem_wait(&mutex);
printf("\n entered thread\n");
sleep(4);
printf("\n exit thread \n");
sem_post(&mutex);
}
int main(){
sem_init(&mutex,0,1);
pthread_t t1,t2;
pthread_create (&t1,NULL,thread,NULL);
sleep(2);
pthread_create(&t2,NULL,thread,NULL);
pthread_join(t1,NULL);
pthread_join(t2,NULL);
sem_destroy(&mutex);
return 0;
}
OUTPUT:
RESULT:
Thus the program to implement mutual exclustion by semaphore is executed and verified successfully.
Ex no : 7 IMPLEMENTATION OF BANKERS ALGORITHM FOR DEAD LOCK
Date : AVOLDANCE
AIM:
ALGORITHM:
PROGRAM CODING
#include<stdio.h>
int main(){
int n,r,i,j,k,p,u=0,s=0,m;
int block[10],run[10],active[10],newreq[10];
int max[10][10],resalloc[10][10],resreq[10][10];
int totalloc[10],totext[10],simalloc[10];
printf("enter the no of processor:");
scanf("%d",&n);
printf("enter the no of resource classes:");
scanf("%d",&r);
printf("enter the total existed resources in each class :");
for(k=1;k<=r;k++)
scanf("%d",&totext[k]);
printf("enter the allocated resources:");
for(i=1;i<=n;i++)
for(k=1;k<=r;k++)
scanf("%d",&resalloc[i][k]);
printf("enter the process making the new request:");
scanf("%d",&p);
printf("enter the request resource:");
for(k=1;k<=r;k++)
scanf("%d",&newreq[k]);
printf("enter the process which are n blocked or running:");
for(i=1;i<=n;i++)
{
if(i!=p)
{
printf("process %d :\n",i+1);
scanf("%d%d",&block[i],&run[i]);
}}
block[p]=0;
run[p]=0;
for(k=1;k<=r;k++){
j=0;
for(i=1;i<=n;i++){
totalloc[k]=j+resalloc[i][k];
j=totalloc[k];
}}
for(i=1;i<=n;i++){
if(block[i]==1||run[i]==1)
active[i]=1;
else
active[i]=0;
}
for(k=1;k<=r;k++){
resalloc[p][k]+=newreq[k];
totalloc[k]+=newreq[k];
}
for(k=1;k<=r;k++){
if(totext[k]-totalloc[k]<0){
u=1;
break;
}}
if(u==0)
{
for(k=1;k<=r;k++)
simalloc[k]=totalloc[k];
for(s=1;s<=n;s++)
for(i=1;i<=n;i++){
if(active[i]==1){
j=0;
for(k=1;k<=r;k++){
if((totext[k]-simalloc[k])<(max[i][k]-resalloc[i][k]))
{
j=1;
break;
}}}
if(j==0){
active[i]==0;
for(k=1;k<=r;k++)
simalloc[k]=resalloc[i][k];
}}
m=0;
for(k=1;k<=r;k++)
resreq[p][k]=newreq[k];
printf("deadlock willnot occur");
}
else{
for(k=1;k<=r;k++){
resalloc[p][k]=newreq[k];
totalloc[k]=newreq[k];
}
printf("deadlock will occur");
}
return 0;
}
OUTPUT:
RESULT:
Thus the bankers algorithm is executed and verified successfully.
Ex no : 8 IMPLEMENTATION OF DEADLOCK DETECTION ALGORITHM
Date :
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
void main(){
int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
printf("enter total no of processors:");
scanf("%d",&tp);
printf("enter total no of resources");
scanf("%d",&tr);
printf("enter claim(max need) matrix \n");
for(i=1;i<=tp;i++){
printf("process %d: \n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("enter the allocation matrix \n");
for(i=1;i<=tp;i++){
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
printf("enter the resource vector (total resources):\n");
for(i=1;i<=tr;i++)
scanf("%d",&r[i]);
printf("enter the availability vector(available resources):\n");
for(i=1;i<=tr;i++){
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=tp;i++){
sum=0;
for(j=1;j<=tr;j++)
sum+=p[i][j]; if(sum==0){ m[k]=i; k++; }
} for(i=1;i<=tp;i++){ for(l=1;l<k;l++){
if(i!=m[l]){ flag=1; for(j=1;j<=tr;j++)
if(c[i][j]<temp[j]){ flag=0; break; }
}
if(flag==1){
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processors
are:");
for(j=1;j<=tp;j++){
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
}
OUTPUT:
RESULT:
Thus the program for deadlock detection is executed and verified successfully.
Ex no : 9 IMPLEMENTATION OF THREADING
Date :
AIM:
To implement threading
ALGORITHM:
PROGRAM CODING
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
void* dosomething(void *arg){
unsigned long i=0;
counter+=1;
printf("\n job %d started\n",counter);
for(i=0;i<(0xFFFFFFFF);i++);
printf("\n job %d finished \n",counter);
return NULL;
}
int main(void){
int i=0;
int err;
while(i<2){
err=pthread_create(&(tid[i]),NULL,&dosomething,NULL);
if(err!=0)
printf("\n can't create thread :
[%s]",strerror(err)); i++; }
pthread_join(tid[0],NULL);
pthread_join(tid[1],NULL); return 0; }
OUTPUT:
RESULT:
Date :
AIM:
To implement paging technique
ALGORITHM:
PROGRAM CODING
#include<stdio.h>
int main(){
int i,j,arr[100],pt[100],val,pgno,offset,phymem,fs,nf;
printf("\n memory management paging \n");
printf("\n enter the size of physical memory");
scanf("%d",&phymem);
for(i=20,j=0;i<phymem+20,j<phymem;i++,j++)
arr[i]=j;
printf("enter the size of the frame or page");
scanf("%d",&fs);
nf=phymem/fs;
printf("no of frame available are \t %d ",nf);
printf("enter the page table");
for(i=0;i<nf;i++)
scanf("%d",&pt[i]);
printf("\n enter th page no");
scanf("%d",&pgno);
printf("enter the offset");
scanf("%d",&offset);
val=(fs*pt[pgno])+offset;
printf("the physical address is %d\n",val);
return 0;
}
OUTPUT:
RESULT:
Thus the paging technique using c program is executed and verified successfully.
Ex no : 11 IMPLEMENTATION OF MEMORY ALLOCATION METHOD
i) FIRST FIT
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
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);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
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]);
getch();
}
OUTPUT:
RESULT:
Thus the First Fit memory allocation method using c program is executed and verified successfully.
ii) WORST FIT
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();
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);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++) {printf("Block %d:",i);scanf("%d",&b[i]);}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++) {printf("File %d:",i);scanf("%d",&f[i]);}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
ff[i]=j;
highest=temp;
}
}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
} printf("\nFile_no:\tFile_size
:\tBlock_no:\tBlock_size:\tFragement"); 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]);
getch();
}
OUTPUT:
RESULT:
Thus the Worst Fit memory allocation method using c program is executed and verified successfully.
iii) BEST FIT:
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.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];
clrscr();
printf("\n\tMemory Management Scheme - Best Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++) {printf("Block %d:",i);
scanf("%d",&b[i]);}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++) {printf("File %d:",i);
scanf("%d",&f[i]);}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
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]);
getch()
}
OUTPUT:
RESULT:
Thus the Best Fit memory allocation method using c program is executed and verified successfully.
Ex no : 12 IMPLEMENTATION OF PAGE REPLACEMENT ALGORITHM
Date :
i) FIFO:
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
int main()
{ int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}
OUTPUT:
RESULT:
Thus the FIFO page replacement algorithm using c program is executed and verified successfully.
ii) LRU
AIM:
ALGORITHM :
PROGRAM:
#include<stdio.h>
int main()
{ int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{ c1=0;
for(j=0;j<f;j++)
{ if(p[i]!=q[j])
c1++;
}
if(c1==f)
{ c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
} else
{
for(r=0;r<f;r++)
{ c2[r]=0;
for(j=i-1;j<n;j--)
{ if(q[r]!=p[j])
c2[r]++;
else
break;
}}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{ if(b[r]<b[j])
{ t=b[r];
b[r]=b[j];
b[j]=t;
}}}
for(r=0;r<f;r++)
{ if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}}}
printf("\nThe no of page faults is %d",c);
}
OUTPUT:
RESULT:
Thus the LRU page replacement algorithm using c program is executed and verified successfully.
iii) OPTIMAL
AIM:
ALGORITHM :
PROGRAM:
#include<stdio.h>
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos,
max, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter page reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
flag3 =0;
for(j = 0; j < no_of_frames; ++j){
temp[j] = -1;
for(k = i + 1; k < no_of_pages; ++k){
if(frames[j] == pages[k]){
temp[j] = k; break; } } } for(j = 0; j <
no_of_frames; ++j){ if(temp[j] == -1){
pos = j;
flag3 = 1;
break;
}
}
if(flag3 ==0){
max = temp[0];
pos = 0;
for(j = 1; j < no_of_frames; ++j){
if(temp[j] > max){
max = temp[j];
pos = j;
}
}
}
frames[pos] = pages[i];
faults++;
}
printf("\n");
for(j = 0; j < no_of_frames; ++j){
printf("%d\t", frames[j]);
}
}
printf("\n\nTotal Page Faults = %d",
faults);
return 0;
}
OUTPUT:
RESULT:
Thus the OPTIMAL page replacement algorithm using c program is executed and verified successfully.
Ex no : 13 IMPLEMENTATION OF FILE ORGANIZATION TECHNIQUE
Date :
AIM:
ALGORITHM:
PROGRAM:(single-level directory)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct
{ char dname[10],fname[10][10];
int fcnt;
}dir;
int main()
{ int i,ch;
char f[30];
dir.fcnt = 0;
printf("\nEnter name of directory -- ");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n 1. Create File\t2. Delete File\t3. Search File \n 4. Display Files\t5. Exit\nEnter your
choice -- ");
scanf("%d",&ch);
switch(ch)
{ case 1: printf("\n
Enter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2: printf("\n Enter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{ if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
}} if(i==dir.fcnt)
printf("File %s not found",f);
else
dir.fcnt--;
break;
case 3: printf("\n Enter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{ if(strcmp(f, dir.fname[i])==0)
{
printf("File %s is found ", f);
break;
}} if(i==dir.fcnt)
printf("File %s not found",f);
break;
case 4: if(dir.fcnt==0)
printf("\n Directory Empty");
else
{
printf("\n The Files are -- ");
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
}
break;
default: exit(0);
}}}
OUTPUT:
RESULT:
Thus the program single level directory file organization technique is executed successfully and output is
ver if ied.
ii) TWO LEVEL DIRECTORY
AIM:
ALGORITHM:
PROGRAM:(Two-level directory)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct
{ char dname[10],fname[10][10];
int fcnt;
}dir[10];
int main()
{ int i,ch,dcnt,k;
char f[30], d[30];
dcnt=0;
while(1){
printf("\n\n 1. Create Directory\t 2. Create File\t 3. Delete File");
printf("\n 4. Search File \t \t 5. Display \t 6. Exit \t Enter your choice -- ");
scanf("%d",&ch);
switch(ch){
case 1: printf("\n Enter name of directory -- ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
case 2: printf("\n Enter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0){
printf("Enter name of the file -- ");
scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;
printf("File created");
break;
} if(i==dcnt)
printf("Directory %s not found",d);
break;
case 3: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
{ if(strcmp(d,dir[i].dname)==0){
printf("Enter name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{ if(strcmp(f, dir[i].fname[k])==0){
printf("File %s is deleted ",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}}
printf("File %s not found",f);
goto jmp;
}}
printf("Directory %s not found",d);
jmp : break;
case 4: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++){
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter the name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
{ if(strcmp(f, dir[i].fname[k])==0)
{
printf("File %s is found ",f);
goto jmp1;
}}
printf("File %s not found",f);
goto jmp1;
}}
printf("Directory %s not found",d);
jmp1: break;
case 5: if(dcnt==0)
printf("\nNo Directory's ");
else
{
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
}}
break;
default:exit(0);
}}}
OUTPUT:
RESULT:
Thus the program single level directory file organization technique is executed successfully and output is
ver if ied.
Ex no : 14 IMPLEMENTATION OF FILE ALLOCATION STRATEGIES
Date :
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{ int f[50],i,st,len,j,c,k,count=0;
for(i=0;i<50;i++)
f[i]=0;
printf("Files Allocated are :\n");
x:count=0;
printf("Enter starting block and length of files: ");
scanf("%d%d",&st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0)
count++;
if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("%d\t%d\n",j,f[j]);
} if(j!=(st+len-1))
printf("The file is allocated to disk\n");
} else
printf("The file is not allocated \n");
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d",&c);
if(c==1)
goto x;
else
exit(0);
}
OUTPUT: lab-3-27@GCECSE-27:~$ gcc -o
ex14seq ex14seq.c
lab-3-27@GCECSE-27:~$ ./ex14seq
Files Allocated are :
Enter starting block and length of files: 1 3
11
21
31
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 4 5
41
51
61
71
81
The file is allocated to disk
Do you want to enter more file(Yes - 1/No - 0)1
Enter starting block and length of files: 7 2
The file is not allocated
Do you want to enter more file(Yes - 1/No - 0)0
lab-3-27@GCECSE-27:~$
RESULT:
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{ int f[50],index[50],i,n,st,len,j,c,k,ind,count=0;
for(i=0;i<50;i++)
f[i]=0;
x:printf("Enter the index block: ");
scanf("%d",&ind);
if(f[ind]!=1)
{
printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);
scanf("%d",&n);
} else
{
printf("%d index is already allocated \n",ind);
goto x;
}
y: count=0;
for(i=0;i<n;i++)
{s
canf("%d",&index[i]);
if(f[index[i]]==0)
count++;
} if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
printf("Allocated\n");
printf("File Indexed\n");
for(k=0;k<n;k++)
printf("%d ------- >%d : %d\n",ind,index[k],f[index[k]]);
} else
{
printf("File in the index is already allocated \n");
printf("Enter another file indexed");
goto y;
}
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
}
OUTPUT:
RESULT:
AIM:
ALGORITHM:
PROGRAM:
RESULT:
Date :
i)FCFS:
AIM:
To implement FCFS disk scheduling algorithm
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<math.h>
int size = 8;
void FCFS(int arr[],int head)
{
int seek_count = 0;
int cur_track, distance;
for(int i=0;i<size;i++)
{
cur_track = arr[i];
// calculate absolute distance
distance = fabs(head - cur_track);
// increase the total count
seek_count += distance;
// accessed track is now new head
head = cur_track;
}
printf("Total number of seek operations: %d\n",seek_count);
// Seek sequence would be the same
// as request array sequence
printf("Seek Sequence is\n");
for (int i = 0; i < size; i++) {
printf("%d\n",arr[i]);
}
}
//Driver code
int main()
{
// request array
int arr[8] = { 176, 79, 34, 60, 92, 11, 41, 114 };
int head = 50;
FCFS(arr,head);
return 0;
}
OUTPUT: lab-3-27@GCECSE-27:~$ gcc -o
fcfsdisk fcfsdisk.c
lab-3-27@GCECSE-27:~$ ./fcfsdisk
Total number of seek operations: 510
Seek Sequence is
176
79
34
60
92
11
41
114
lab-3-27@GCECSE-27:~$
RESULT:
Thus the FCFS disk scheduling algorithm is executed and verified successfully.
ii)SSTF
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{ int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{ int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
}}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the SSTF disk scheduling algorithm is executed and verified successfully.
iii)SCAN(ELEVATOR)
AIM:
ALGORITHM:
PROGRAM(SCAN):
#include<stdio.h>
#include<stdlib.h>
int main()
{ int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
// logic for Scan disk scheduling
/*logic for sort the request array */
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{ if(RQ[j]>RQ[j+1])
{ int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}}} int index;
for(i=0;i<n;i++)
{ if(initial<RQ[i])
{ index=i;
break;
}} // if movement is towards high value
if(move==1)
{
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
} // last movement for max size
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
initial = size-1;
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}} // if movement is towards low value
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
} // last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the SCAN disk scheduling algorithm is executed and verified successfully.
iv) C-SCAN
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{ int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
// logic for C-Scan disk scheduling
/*logic for sort the request array */
for(i=0;i<n;i++)
{
for( j=0;j<n-i-1;j++)
{ if(RQ[j]>RQ[j+1])
{ int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}
}} int index;
for(i=0;i<n;i++)
{ if(initial<RQ[i])
{ index=i;
break;
}}
// if movement is towards high value
if(move==1)
{
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for max size
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
/*movement max to min disk */
TotalHeadMoment=TotalHeadMoment+abs(size-1-0);
initial=0;
for( i=0;i<index;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}} // if movement is towards low value
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
} // last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
/*movement min to max disk */
TotalHeadMoment=TotalHeadMoment+abs(size-1-0);
initial =size-1;
for(i=n-1;i>=index;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
lab-3-27@GCECSE-27:~$ gcc -o
cscan cscan.clab-3-27@GCECSE-
27:~$ ./cscan
Enter the number of
Requests8
Enter the Requests
sequence95 180
34 119 11 123 62
64
Enter initial head
position50 Enter
total disk
size200
Enter the head movement direction for high 1 and for
low 01
Total head movement is 382
RESULT:
Thus the SCAN disk scheduling algorithm is executed and verified successfully.
Ex no : 16 INSTALL ANY GUEST OPERATING SYSTEM LIKE LINUX USING
VM WARE
Date :
AIM:
PROCEDURE:
Step 6: Select installer disc image file and browse for the downloaded ubuntu iso file location and select the
iso file and click Next.
Step 7: Give Fullname, Username, Password and click Next.
Step 8: Give the Virtual Machine name as Ubuntu and click Next.
Step 9: Specify the disk capacity as per the availability of space in your PC.