OS Lab - Odt
OS Lab - Odt
AIM:
To install Windows Operating System.
DESCRIPTION:
Windows XP is a versatile O.S. which took over various laggings in the earlier O.S
given by Microsoft. One major component which really improves the performance and working
is the availability of various device drivers which really make device operation as simple as
plug-n-play. If the minimum system requirement is not fulfilled then you will not be able to
install this O.S. on to your machine, however, Windows 98 might serve the purpose. Windows
XP is in huge demand globally, let us learn how to load it before making us to work on it.
System Requirements
System Requirements Minimum Recommended
Processor 233MHz 300 MHz or higher
Memory 64 MB RAM 128 MB RAM or higher
Video adapter and Monitor Super VGA (800 x 600) or higher resolution
Hard drive disk free space 1.5 GB or higher
Drives CD-ROM drive or DVD drive
Input Devices Keyborad, Microsoft Mouse
Sound Speakers. Sound card, Head Phones
Installation Steps
The following step by step procedure will help you to install Windows XP. The installation
procedure is shown with the figure appears on your screen after doing a step.
1) Insert the Windows XP CD into your computer and restart.
2) If prompted to start from the CD, press SPACEBAR. If you miss the prompt (it only
appears for a few seconds), restart your computer to try again.
3) Windows XP Setup begins. During this portion of setup, your mouse will not work, so
you must use the keyboard. On the Welcome to Setup page, press ENTER.
4) On the Windows XP Licensing Agreement page, read the licensing agreement. Press the
PAGE DOWN key to scroll to the bottom of the agreement. Then press F8.
5) Next page enables you to select the hard disk drive on which Windows XP will be
installed. Once you complete this step, all data on your hard disk drive will be removed and
cannot be recovered. It is extremely important that you have a recent backup copy of your
files before continuing. When you have a backup copy, press D, and then press L when
prompted. This deletes your existing data.
6) Press ENTER to select Unpartitioned space, which appears by default.
7) Press ENTER again to select Format the partition using the NTFS file system, which
appears by default.
8) Windows XP erases your hard disk drive using a process called formatting and then copies
the setup files. You can leave your computer and return in 20 to 30 minutes
9) Windows XP restarts and then continues with the installation process. From this point
forward, you can use your mouse. Eventually, the Regional and Language Options page
appears. Click Next to accept the default settings. If you are multilingual or prefer a language
other than English, you can change language settings after setup is complete.
10) On the Personalize Your Software page, type your name and your organization name.
Some programs use this information to automatically fill in your name when required. Then,
click Next.
11) On the Your Product Key page, type your product key as it appears on your Windows XP
CD case. The product key is unique for every Windows XP installation. Then, click Next.
12) On the Computer Name and Administrator Password page, in the Computer name box,
type a name that uniquely identifies your computer in your house, such as FAMILYROOM
or TOMS. You cannot use spaces or punctuation. If you connect your computer to a network,
you will use this computer name to find shared files and printers. Type a strong password
that you can remember in the Administrator password box, and then retype it in the Confirm
password box. Write the password down and store it in a secure place. Click Next.
13) On the Date and Time Settings page, set your computer’s clock. Then, click the Time
Zone down arrow, and select your time zone. Click Next.
14) Windows XP will spend about a minute configuring your computer. On the Networking
Settings page, click Next.
15) On the Workgroup or Computer Domain page, click Next.
16) Windows XP will spend 20 or 30 minutes configuring your computer and will
automatically restart when finished. When the Display Settings dialog appears, click OK.
17) When the Monitor Settings dialog box appears, click OK.
18) The final stage of setup begins. On the Welcome to Microsoft Windows page, click Next.
19) On the Help protect your PC page, click Help protect my PC by turning on Automatic
Updates now. Then, click Next
20) Windows XP will then check if you are connected to the Internet:
If you are connected to the Internet, select the choice that describes your network connection
on the Will this computer connect to the Internet directly, or through a network? page. If
you’re not sure, accept the default selection, and click Next.
21) If you use dial-up Internet access, or if Windows XP cannot connect to the Internet, you
can connect to the Internet after setup is complete. On the How will this computer connect to
the Internet? page, click Skip.
22) Windows XP Setup displays the Ready to activate Windows? page. If you are connected
to the Internet, click Yes, and then click Next. If you are not yet connected to the Internet,
click No, click Next, and then skip to step 24. After setup is complete, Windows XP will
automatically remind you to activate and register your copy of Windows XP.
23) On the Ready to register with Microsoft page, click Yes, and then click Next
24) On the Collecting Registration Information page, complete the form. Then, click Next.
25) On the Who will use this computer? page, type the name of each person who will use the
computer. You can use first names only, nicknames, or full names. Then click Next. To add
users after setup is complete or to specify a password to keep your account private, read
Create and customize user accounts.
26) On the Thank you! page, click Finish.
27) Congratulations! Windows XP setup is complete. You can log on by clicking your name
on the logon screen. If you’ve installed Windows XP on a new computer or new hard disk
drive, you can now use the File and Settings Transfer Wizard to copy your important data to
your computer or hard disk drive.
RESULT
Thus the Windows Operating System is installed and Executed successfully.
EX. NO: 2 a STUDY OF BASIC UNIX COMMANDS
DATE :
AIM:
To study the basic commands in UNIX.
COMMANDS:
1. WORKING WITH DIRECTORIES:
Create a Directory:
COMMAND : mkdir
SYNTAX : mkdir DirectoryName
EXPLANATION : Used to create a new directory with the specified name.
EXAMPLE : mkdir student.
Changing the Working Directory:
COMMAND : cd
SYNTAX : cd DirectoryName.
EXPLANATION : Used to switch from one directory to another.
EXAMPLE : cd UnixLab
OPTIONS
cd . . helps to move one level up.
cd \ helps to go to the root directory.
Current Working Directory:
COMMAND : pwd
SYNTAX : pwd
EXPLANATION : Used to know the current working directory.
Removing a directory:
COMMAND : rmdir (or) rd
SYNTAX : rmdir DirectoryName
EXPLANATION : Used to remove the specified directory.
EXAMPLE : rmdir UnixLab.
4. WRAP LINES:
COMMAND : fold
SYNTAX : fold FileName
EXPLANATION : Used to wraps each line in an input file to fit a specified
width and prints it to the standard output..
OPTIONS
fold -b FileName : It is used to limit the width of the output by the number of
bytes.
fold -s FileName : It is used to break the lines on spaces.
6. CLEAR COMMAND:
COMMAND : clear
SYNTAX : clear
EXPLANATION : Used to clear the terminal screen.
7. MAN COMMAND:
COMMAND : man
SYNTAX : man CommandName
EXPLANATION : Used to display the manual of a specific command.
EXAMPLE : man mkdir
8. ALIAS COMMAND:
COMMAND : alias
SYNTAX : alias UnixCommand=’new name’
EXPLANATION : Used to create a shortcut to reference a command.
EXAMPLE : alias rm= 'rm -i'
UNALIAS : Removing an existing alias is known as unaliasing.
COMMAND : unalias
SYNTAX : unalias AliasName
12. LP COMMAND:
. COMMAND : lp
SYNTAX : lp FileName
EXPLANATION : It submits files for printing or alters a pending job.
EXAMPLE:
1. lp -c -n30 -d Devicename FileName
To print 30 copies of the given File Name using a copy of the file.
2. lp -c -m -n30 -d Devicename FileName
To print 30 copies of the given File Name using a copy of the file, and to
notify the user that the job is completed using mail.
RESULT
Thus the basic Unix Commands was studied and executed successfully.
EX: NO: 2 b IMPLEMENTATION OF SHELL PROGRAMS
DATE :
AIM:
To implement simple Shell Programs to do basic Arithmetic operations,
Conditional Statements and Looping Statements.
Step 2: Give the expressions for Sum, Difference, Product and Quotient and solve them.
OUTPUT:
ponjesly@ponjesly-desktop:~$ sh arith.sh
Enter two numbers
20
5
Sum = 25
Difference = 15
Product = 100
Quotient = 4
OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh sum1.sh
Enter Size(N)
5
Enter Numbers
1
2
3
4
5
Sum of given 5 Numbers is 15
OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh factorial.sh
Enter a number
5
Enter Numbers
The factorial of 5 is 120
ALGORITHM:.
Step 1: Read the value of num.
Step 2: Calculate r=expr $num%2
Step 3: If the value of rem equals 0 then print the number is even
Step 4: If the value of rem not equal to 0 then print the number is odd.
PROGRAM:
echo "Enter a number : "
read num
rem=`expr $num % 10`
if [ $rem -eq 0 ]
then
echo "$num is an Even Number"
else
echo "$num is an Odd Number"
fi
OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh odd.sh
Enter a values :
12
12 is an Even Number
ponjesly@ponjesly-desktop:~/geetha$ sh odd.sh
Enter a values :
25
12 is an Odd Number
Shell program to find the greatest among the given three numbers
ALGORITHM:
Step 1: Take three inputs from the user
Step 2: In if-else condition, check which is the greatest
Step 3: Also check with the third number
Step 4: Find the result
Step 5: print the result
PROGRAM:
echo "Enter 3 values :"
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is the Biggest number"
elif [ $b -gt $c ]
then
echo "B is the Biggest number"
else
echo "C is the Biggest number"
fi
OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
12 45 8
B is the Biggest number
ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
56 23 17
A is the Biggest number
ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
12 56 89
C is the Biggest number
RESULT:
Thus the above Shell programs was executed successfully.
EX: NO: 3 PROCESS MANAGEMENT USING SYSTEM CALLS
DATE :
AIM:
To implement UNIX System calls in C.
ALGORITHM:
1. Create a child process using fork system call.
2. If return value is -1 then Print "Process creation failure"
Terminate using exit system call.
3.If pid>0 Print "Parent process"
Print process id of the parent using getpid system call
Print even number
4. Otherwise Print "Child process" Print process id of the child using getpid system call
Print odd number
5. Stop
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
main()
{
int i;
pid_t pid;
pid = fork();
if (pid < 0)
{
printf("\nProcess creation failure\n");
exit(-1);
}
else if(pid > 0)
{
wait(NULL);
printf ("\nParent starts ");
printf("\nProcess id of child is %d", getpid());
printf ("\nEven Nos: ");
for (i=2;i<=10;i+=2)
printf ("%3d",i);
printf ("\nParent ends\n");
}
else
{
printf ("Child starts ");
printf("\nChild Process id is %d", getpid());
printf ("\nOdd Nos: ");
for (i=1;i<10;i+=2)
printf ("%3d",i);
printf ("\nChild ends\n");
}
close(pid);
}
OUTPUT:
Child starts
Child Process id is 4275
Odd Nos: 1 3 5 7 9
Child ends
Parent starts
Process id of child is 4274
Even Nos: 2 4 6 8 10
Parent ends
RESULT:
Thus the above programs implement UNIX System calls C was written and executed
successfully.
EX: NO:4 a IMPLEMENTATION OF FIRST COME FIRST SERVE (FCFS) CPU SCHEDULING
DATE :
AIM:
To implement First Come First Serve (FCFS) CPU Scheduling in C language.
ALGORITHM:
• Get the Number of Process and CPU burst time for all the processes.
• Calculate the waiting time according to the process that was first entered and then
the next it continued all the processes get executed.
• Calculate the turnaround time.
• Find the average waiting time and average turnaround time.
• Display all the details for each process.
PROGRAM:
#include<stdio.h>
int main( )
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes: ");
scanf("%d",&n);
printf("\nEnter Process Burst Time\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
wt[0]=0; //waiting time for first process is 0
for(i=1;i<n;i++) //calculating waiting time
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++) //calculating turnaround time
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\n%d\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
OUTPUT:
Enter total number of processes: 4
Enter Process Burst Time
3
6
4
2
Process Burst Time Waiting Time Turnaround Time
1 3 0 3
2 6 3 9
3 4 9 13
4 2 13 15
Average Waiting Time:6
Average Turnaround Time:10
RESULT:
Thus the program implement First Come First Serve (FCFs) CPU Scheduling was done
and executed successfully.
DATE:
AIM:
To implement Shortest Job First (SJF) CPU Scheduling in C language.
ALGORITHM:
• Get the Number of Process and CPU burst time for all the processes.
• Calculate the waiting time such that the process with the shortest CPU burst time is
executed first and the processes with the largest CPU burst time is executed last.
• Calculate the turnaround time.
• Find the average waiting time and average turnaround time.
• Display all the details for each process.
PROGRAM:
#include<stdio.h>
void main( )
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}
//sorting burst time in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0; //waiting time for first process will be zero
//calculate waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}
OUTPUT:
Enter number of process: 4
Enter Burst Time:
3
6
4
2
Process Burst Time Waiting Time Turnaround Time
p4 2 0 2
p1 3 2 5
p3 4 5 9
p2 6 9 15
RESULT:
Thus the program implement Shortest Job First (SJF) CPU Scheduling was done and
executed successfully.
RESULT:
Thus the program implement Priority CPU Scheduling was done and executed successfully.
2 2 1
3 3 1
4 5 4
5 13 8
1 19 9
AIM:
To implement interprocess communication using shared memory.
ALGORITHM:
Create the child process using fork( ).
Create the shared memory for parent process using shmget( ) system call.
Now allow the parent process to write in shared memory using shmget pointer which is
return type of shmat( ).
Now across and attach the same shared memory to the child process.
The data in the shared memory is read by the child process.
Now detach and rebase the shared memory.
PROGRAM:
#include<stdio.h>
#include<sys/shm.h>
#include<sys/ipc.h>
void main( )
{
int child,shmid,i;
char *shmptr;
child=fork( );
if(!child)
{
shmid=shmget(2041,32,0666|IPC_CREAT);
shmptr=shmat(shmid,0,0);
printf("\n\tINTERPROCESS COMMUNICATION USING SHARED MEMORY\n");
printf("\n\t*******************************************\n");
printf("\nParent Writing:");
for(i=0;i<25;i++)
{
shmptr[i]='a'+i;
putchar(shmptr[i]);
}
wait(NULL);
}
else
{
shmid=shmget(2041,32,0666);
shmptr=shmat(shmid,0,0);
printf("\n\nChild is Reading:");
for(i=0;i<25;i++)
putchar(shmptr[i]);
printf("\n\n");
shmdt(NULL);
shmctl(shmid,IPC_RMID,NULL);
}
}
OUTPUT:
Child is Reading:abcdefghijklmnopqrstuvwxy
INTERPROCESS COMMUNICATION USING SHARED MEMORY
*******************************************
Parent Writing:abcdefghijklmnopqrstuvwxy
CONCLUSION:
Thus the program to implement the interprocess communication using shared
memory was executed successfully.
ALGORITHM:
Initialize the Semaphore mutex, full & empty.
In the case of producer process, Produces a value.
i) If there is empty space in the buffer check the mutex value.
ii) If the mutex value is 0, allow the producer to add value to the buffer.
iii) Signal the mutex value and increment the full value by 1.
In the case of consumer process, Consumes a value
i) If there is any value in the buffer check for mutex value.
ii) If the mutex value is 0, remove value from buffer
iii) Signal the mutex value and increment the empty value by 1.
Print the result.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void producer( );
void consumer( );
int wait(int);
int signal(int);
int mutex=1,full=0,empty=3,x=0;
void main( )
{
int n;
printf("\n1.Producer\n2.Consumer\n3.Exit\n");
while(1)
{
printf("\nEnter your Choice");
scanf("%d",&n);
switch(n)
{
case 1:
if((mutex==1)&&(empty!=0))
producer( );
else
printf("buffer is full\n");
break;
case 2:
if((mutex==1)&&(full!=0))
consumer( );
else
printf("buffer is empty");
break;
case 3:
exit(0);
break;
}
}
}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer( )
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\nProduced value %d",x);
mutex=signal(mutex);
}
void consumer( )
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\nConsumed value %d",x);
x--;
mutex=signal(mutex);
}
OUTPUT:
1.Producer
2.Consumer
3.Exit
RESULT:
Thus the above program to implement Produce-Consumer relationship using
Semaphore was done successfully.
DATE:
AIM:
To implement Deadlock Avoidance using Banker’s Algorithm in C language.
ALGORITHM:
Get the number of Processes and Resources.
Get the Allocation and Max Matrix.
Get the Available vector.
Find the Need Matrix using, Need=Max-Allocation
Use Banker’s Algorithm to check Need<=work is True for all processes.
If it is true for all process then the system is in safe state. So print the Safe Sequence.
Otherwise system is not in safe state.
PROGRAM:
#include <stdio.h>
void main( )
{
int n, m, i, j, k, ind = 0;
int alloc[10][10], max[10][10], avail[10], f[n], ans[n];
printf("Enter the No. of Process "); scanf("%d",&n);
printf("Enter the No. of Resources "); scanf("%d",&m);
printf("Enter the values for Allocation Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the values for Max Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter Available vector");
for(i=0;i<m;i++)
{
scanf("%d",&avail[i]);
}
for (k = 0; k < n; k++)
{
f[k] = 0;
}
int need[n][m];
printf("Need Matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
need[i][j] = max[i][j] - alloc[i][j];
printf("%d\t",need[i][j]);
}
printf("\n");
}
int y = 0;
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)
{
if (need[i][j] > avail[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
printf("The Safe Sequence is: ");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
OUTPUT:
Enter the No. of Process 5
Enter the No. of Resources 3
Enter the values for Allocation Matrix
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
Enter the values for Max Matrix
7 5 3
3 2 2
9 0 2
2 2 2
4 3 3
Enter Available vector
3 3 2
Need Matrix
7 4 3
1 2 2
6 0 0
0 1 1
4 3 1
The Safe Sequence is: P1 -> P3 -> P4 -> P0 -> P2
RESULT:
Thus the program implement Deadlock Avoidance using Banker’s Algorithm was
done and executed successfully.
DATE:
AIM:
To implement Deadlock Detection Algorithm in C language.
ALGORITHM:
Get the number of Processes and Resources.
Get the Allocation and Request Matrix.
Get the Available vector.
Use Deadlock Detection Algorithm to check Request<=work is True for all processes.
If it is true for all process then the system is in safe state.
Otherwise system is not in safe state.
PROGRAM:
#include <stdio.h>
void main( )
{
int n, m, i, j, k, y = 0, ind=0;
int alloc[10][10], req[10][10], avail[10], f[n], ans[n];
printf("Enter the No. of Process ");
scanf("%d",&n);
printf("Enter the No. of Resources ");
scanf("%d",&m);
printf("Enter the values for Allocation Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the values for Request Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&req[i][j]);
}
}
printf("Enter Available vector");
for(i=0;i<m;i++)
{
scanf("%d",&avail[i]);
}
for (k = 0; k < n; k++)
{
f[k] = 0;
}
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)
{
if (req[i][j] > avail[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
printf("The Safe Sequence is: ");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
OUTPUT:
Enter the No. of Process 5
RESULT:
Thus the program implement Deadlock Detection was done and executed
successfully.
PROGRAM:
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
sem_t mutex;
static int count;
void* thread(void* arg)
{
sem_wait(&mutex);
count++;
printf("\nThread %d Created",count);
sleep(4);
printf("\nThread %d Exited",count);
sem_post(&mutex);
}
void 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);
}
OUTPUT:
Thread 1 Created
Thread 1 Exited
Thread 2 Created
Thread 2 Exited
RESULT:
Thus the above program to implement threading was done successfully.
DATE:
AIM:
#include<stdio.h>
main()
{
int np,ps,i;
int *sa;
printf("Enter Number of pages: ");
scanf("%d",&np);
printf("Enter Page size: ");
scanf("%d",&ps);
sa=(int*)malloc(2*np);
for(i=0;i<np;i++)
{
sa[i]=(int)malloc(ps);
printf("Page No %d\tAddress - %d\n",i+1,sa[i]);
}
}
OUTPUT:
Enter Number of pages: 5
Enter Page size: 3
Page No 1 Address - 3308800
Page No 2 Address - 3308832
Page No 3 Address - 3308864
Page No 4 Address - 3308896
Page No 5 Address - 3308928
RESULT:
Thus the program to implement Paging Memory management was done successfully.
DATE:
AIM:
To write a program to implement Memory Management methods using First Fit, Best Fit
and Worst Fit.
ALGORITHM:
In best fit, allocate the elements in the smallest hole that is being enough.
In the first fit, allocate the first hole that is big enough.
Display the allocation of files in memory block and the remaining amount of memory.
#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("\nFirst Fit Memory Management");
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\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]);
}
OUTPUT:
First Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3
OUTPUT:
Best Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3
OUTPUT:
Worst Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3
RESULT:
Thus the above program to implement Memory Management methods using First Fit,
Best Fit and Worst Fit was done successfully.
AIM:
To write a program to implement Page Replacement algorithms using FIFO, LRU and
LFU using C Programs.
ALGORITHM:
Declare the needed variables.
Get the number of page reference.
Get the reference string as input.
Get the number of frames needed.
Using the page replacement algorithms find the page faults.
FIFO – Replace the first inserted page.
LRU – Replace the page that was used most recently.
LFU – Replace the page that was having least frequency count.
Finally replace the total number of page faults.
OUTPUT:
Enter the length of reference string 7
Enter the reference string 1
3
0
3
5
6
3
Enter no. of frames 3
The Page Replacement Process is
1 -1 -1
1 3 -1
1 3 0
1 3 0
5 3 0
5 6 0
5 6 3
The number of Page Faults using FIFO is 6
OUTPUT:
Enter the length of reference string 7
Enter the reference string 1
3
0
3
5
6
3
Enter the number of frames 3
The Page Replacement process is
1 -1 -1
1 3 -1
1 3 0
1 3 0
5 3 0
5 3 6
5 3 6
The number of page faults using LRU is 5
RESULT:
Thus the program to implement Page Replacement algorithms using FIFO, LRU and LFU
was done successfully.
AIM:
To write a program to implement different File Organization Methods.
ALGORITHM:
The directory structure is the organization of files into a hierarchy of folders.
In a single-level directory system, all the files are placed in one directory called as
root directory.
In the two-level directory system, each user has own user file directory (UFD). The
system maintains a master block that has one entry for each user. UFD’s present
under the system's master file directory (MFD).
Program: 13(a)- SINGLE LEVEL DIRECTORY STRUCTURE
#include<stdio.h>
#include<stdlib.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main( )
{
int i,ch;
char f[30];
dir.fcnt = 0;
printf("\nEnter name of directory: ");
scanf("%s", dir.dname);
while(1)
{
printf("\n1. Create File\n2. Display Files\n3. Exit\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the name of the file: ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2:
if(dir.fcnt==0)
printf("\nDirectory Empty");
else
{
printf("\nThe Files are: ");
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
}
break;
default:
exit(0);
}
}
}
OUTPUT:
1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Flowers
1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Fruits
1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Vegetables
1. Create File
2. Display Files
3. Exit
Enter your choice: 2
1. Create File
2. Display Files
3. Exit
Enter your choice: 3
OUTPUT:
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 1
Enter name of directory: One
Directory created
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 1
Enter name of directory: Two
Directory created
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: One
Enter name of the file: Subjects
File created
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: One
Enter name of the file: Crafts
File created
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: Two
Enter name of the file: Fruits
File created
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 3
Directory Files
One Subjects Crafts
Two Fruits
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 4
RESULT:
Thus the program to implement different File Organization methods was done
successfully.
AIM:
ALGORITHM:
Declare the needed variables.
Get the number of files
Get the total no. of blocks that needed for each file.
Allocate the memory for each file continuously.
Display the file name, start address and size of the file.
RESULT:
Thus the program to implement different File Allocation methods was done successfully.
AIM:
ALGORITHM:
Start the program
Get the Start head position
Enter movements
Process it and display the result
Stop the program
PROGRAM: 15(a) – FCFS DISK SCHEDULING
#include<stdio.h>
#include<stdlib.h>
void main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
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);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
printf("Total head moment is %d",TotalHeadMoment);
}
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644
RESULT:
Thus the program to implement different disk allocation algorithms was done
successfully.
RESULT
Thus the VMWare is installed successfully