OS Final Record
OS Final Record
0 0 3 1.5
COURSE OBJECTIVES:
LIST OF EXPERIMENTS:
1. Installation of windows operating system
2. Illustrate UNIX commands and Shell Programming
3. Process Management using System Calls : Fork, Exit, Getpid, Wait, Close
4. Write C programs to implement the various CPU Scheduling Algorithms
5. Illustrate the inter process communication strategy
6. Implement mutual exclusion by Semaphore
7. Write C programs to avoid Deadlock using Banker's Algorithm
8. Write a C program to Implement Deadlock Detection Algorithm
9. Write C program to implement Threading
10. Implement the paging Technique using C program
11. Write C programs to implement the following Memory Allocation Methods
a. First Fit b. Worst Fit c. Best Fit
12. Write C programs to implement the various Page Replacement Algorithms
13. Write C programs to Implement the various File Organization Techniques
14. Implement the following File Allocation Strategies using C programs
a. Sequential b. Indexed c. Linked
15. Write C programs for the implementation of various disk scheduling algorithms
16. Install any guest operating system like Linux using VMware.
Exp.No:1 INSTALLATION OF WINDOWS OPERATING SYSTEM
AIM:
PROCEDURE:
Steps to install Windows 10 :
Step 2: Mount the ISO image as a drive or burn it into a DVD. Optionally, you can create a
Windows 10 bootable USB drive.
Step 3: Launch your virtual machine software and create a new virtual machine. You can read
more details on how to install Windows 10 on VMWare Workstation.
Step 4: After you create the virtual machine, follow the steps below to install Windows 10.
Step 5: In the welcome screen, choose your language settings and click the "Next" button to
proceed.
Step 6: Accept the license terms and click "Next" to proceed.
Step 7: In the next step, you have to select the drive to install. If you have multiple drives on
your computer, you will see them all there. Choose the correct drive to install. If you are
installing Windows 10 over an existing Windows, you may install side by side on another
drive.
Step 8: Installer will copy all the necessary files to the computer and continue with the
installation. Depending on your system configuration, it may take a while (10-20 minutes) to
complete the installation.
After successful installation, you will see the Windows welcome screen, which is similar to
the Windows 8 theme.
You will be presented with an option to select the Settings. Unless you want to make custom
configuration, you can choose "Express Settings" and proceed.
In the next step, you will be prompted to select One Drive option. If you don't want to
integrate One Drive storage for this computer, you can Turn Off the One Drive options.
The next step is installing some basic apps for your Windows 10 computer. No intervention
from your side is necessary. Windows will automatically install the apps for you. It may take
several minutes to complete the installation.
As part of installation, you will need to connect your Microsoft account with your OS to
access various services like Microsoft App Store. You will need to use the same Microsoft
account to login to your Windows.
You are all set. In a few minutes, Windows 10 will be configured and will be ready for you to
use. If you encounter any errors or have any suggestions for Microsoft to improve the OS,
don't forget to report them to Microsoft.
RESULT:
EXERCISE 2:ILLUSTRATE UNIX COMMANDS AND SHELL PROGRAMMING
a
b
basename Strip directory and suffix
Again SHell
bg Send to background
c
cal Display a calendar
owner andgroup
of a loop
d
date Display or change the date &time
dc Desk Calculator
op Operator access
ps Process status
apipe
q
quota Display disk usage and
diskusage r
the system
rm Remove files
ss Socket Statistics
V
v Verbosely list directory contents (`ls -l -b')
vi Text Editor
w
w Show who is logged on and what they are doing
whereis Search the user's $path, man pages and source files
for a program
which Search the user's $path for a program
Program code:
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
// if file does not have in directory
// then file foo.txt is created.
int fd = open("foo.txt", O_RDONLY | O_CREAT);
if (fd == -1) {
// print which type of error have in a code
printf("Error Number % d\n", errno);
Output:
Exercise 4:CPU Scheduling algorithm:First come first serve
Program code:
#include<stdio.h>
#include<conio.h>
main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg; clrscr();
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
getch();
return 0;
}
Output:
Exercise5:Illustrate the inter process communication strategy
Program code:
#include <stdio.h>
int main(void) {
int i, my_array[8];
for(i=0;i<=20;i++) {
my_array[i] = i+1;
}
for(i=0;i<8;i++) {
printf("%d\n", my_array[i]);
}
return 0;
}
Output:
Exercise 6:Implement mutual exclusion by semaphore.
Program code:
#include<stdio.h>
void main() {
int buffer[10], bufsize, in, out, produce, consume, choice=0;
in = 0;
out = 0;
bufsize = 10;
while(choice != 3) {
printf("\n1. Produce \t 2. Consume \t 3. Exit");
printf("\nEnter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1:
if((in+1) % bufsize == out) {
printf("\nBuffer is Full");
} else {
printf("\nEnter the value: ");
scanf("%d", &produce);
buffer[in] = produce;
in = (in+1) % bufsize;
}
break;
case 2:
if(in == out) {
printf("\nBuffer is Empty");
} else {
consume = buffer[out];
printf("\nThe consumed value is %d", consume);
out = (out+1) % bufsize;
}
break;
}
}
}
Output:
Exercise 7:Write c program to avoid deadlock using banker’s algorithm.
Program code:
#include<stdio.h>
int main() {
/* array will store at most 5 process with 3 resoures if your process or
resources is greater than 5 and 3 then increase the size of array */
int p, c, count = 0, i, j, alc[5][3], max[5][3], need[5][3], safe[5], available[3], done[5], terminate = 0;
printf("Enter the number of process and resources");
scanf("%d %d", & p, & c);
// p is process and c is diffrent resources
printf("enter allocation of resource of all process %dx%d matrix", p, c);
for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & alc[i][j]);
}
}
printf("enter the max resource process required %dx%d matrix", p, c);
for (i = 0; i < p; i++) {
for (j = 0; j < c; j++) {
scanf("%d", & max[i][j]);
}
}
printf("enter the available resource");
for (i = 0; i < c; i++)
scanf("%d", & available[i]);
}
if (terminate != (p - 1)) {
printf("\n available resource after completion\n");
for (i = 0; i < c; i++) {
printf("%d\t", available[i]);
}
printf("\n safe sequence are\n");
for (i = 0; i < p; i++) {
printf("p%d\t", safe[i]);
}
}
return 0;
}
Output:
Exercise 8:Write a c program to implement deadlock detection algorithm.
Program code:
#include<stdio.h>
static int mark[20];
int i,j,np,nr;
int main()
{
int alloc[10][10],request[10][10],avail[10],r[10],w[10];
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&request[i][j]);
}
}
for(i=0;i<np;i++)
{
int count=0;
for(j=0;j<nr;j++)
{
if(alloc[i][j]==0)
count++;
else
break;
}
if(count==nr)
mark[i]=1;
}
// initialize W with avail
for(j=0;j<nr;j++)
w[j]=avail[j];
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
}
}
}
if(deadlock)
printf("\n Deadlock detected");
else
printf("\n No Deadlock possible");
}
Output:
ExNo 9:Write C program to implement threading.
Program code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // Header file for sleep()
#include <pthread.h>
int main() {
pthread_t thread_id;
printf("Before Thread\n");
printf("After Thread\n");
exit(0);
}
Output:
Exercise 10:Implement the paging technique using c program.
Program code:
#include <stdio.h>
#include <stdlib.h>
#define NUM_FRAMES 4
#define NUM_PAGES 10
#define PAGE_SIZE 1024 // Page size in bytes
int main() {
int frames[NUM_FRAMES] = {-1, -1, -1, -1}; // Represents frames, -1 indicates empty frame
int pages[NUM_PAGES]; // Represents pages
int i, j, page, frame, offset, physical_address;
// Accessing pages
printf("Page\tFrame\tOffset\tPhysical Address\n");
for (i = 0; i < NUM_PAGES; i++) {
page = i;
frame = page % NUM_FRAMES;
offset = page * PAGE_SIZE % PAGE_SIZE;
physical_address = frames[frame] * PAGE_SIZE + offset;
if (frames[frame] == -1) {
frames[frame] = i; // Allocate frame for page
}
return 0;
}
Output:
Exercise11:Write C programs to implement the following memory allocation methods.
Mallac() and free()
Program code:
// Program to calculate the sum of n numbers entered by the user
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, i, *ptr, sum = 0;
return 0;
}
Output:
Ex No:12 Write C programs to implement the various Page
Replacement Algorithms
Program code:
#include <stdio.h>
//user-defined function
int findLRU(int time[], int n)
{
int i, minimum = time[0], pos = 0;
return pos;
}
//main function
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2,
i, j, pos, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
if (flag2 == 0)
{
pos = findLRU(time, no_of_frames);
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
}
printf("\n");
return 0;
}
Output:
Ex No:13 Write C programs to Implement the various File Organization
Techniques: Single level directory organization.
Program code:
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch;
char f[30];
clrscr();
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);
}
}
getch();
}
Output:
Exercise 14:File allocation strategies:sequential
Program code:
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
X:
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1 ;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch();
return 0;
}
Output:
Exercise 15: FCFS (First-Come, First-Serve) Disk Scheduling Algorithm:
Program code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int queue[20],head,n,i;
float seek_time=0;
printf("Enter the size of queue:");
scanf("%d",&n);
printf("Enter the queue elements:");
for(i=0;i<n;i++)
{
scanf("%d",&queue[i]);
}
printf("Enter the head position");
scanf("%d",&head);
for(i=0;i<n;i++){
seek_time+=abs(head-queue[i]);
head=queue[i];
}
printf("Total seek time:%f",seek_time);
return 0;
}
Output:
Ex no:16 Install any guest operating system like Linux using VMware
Program:
Choose Your Preferred Linux OS
You probably know which Linux OS you want to try. Some Linux distros are
particularly suited to running in a VM, but others are not. All 32-bit and 64-bit
distros work in a virtual machine. However, you cannot run Linux distros for
ARM architecture (such as the Raspberry Pi) in VMware.
Should you want to emulate an ARM environment in Windows, try QEMU.
If you don't know which OS to choose, however, you'll find our regularly-
updated list of the best Linux distributions here.
With the operating system selected and configured, it's time to build the virtual
machine.
In some cases, you might need to customize the virtual machine before
installing Linux. Alternatively, you might install the OS and find there is
something missing.
To fix this, right-click your virtual machine in VMware Workstation Player and
select Settings.
Here, you can tweak the virtual machine's hardware in other ways beyond the
HDD. You have options for the Memory, Processors, Network
Adaptor configuration, and much more.
It's worth taking a look at the Processors screen. In the right-hand pane, you'll
spot a reference to a Virtualization engine. By default, this works automatically,
but for troubleshooting set Intel VT-x or AMD-V, depending on your CPU.
You can address performance issues in the Memory screen. Here you'll spot an
illustration of the suggested RAM size, as well as recommended options for your
virtual machine. It's a good idea to stick to these recommendations.
Going too small will prove a problem, while setting the RAM too high will impact
on your PC's performance, slowing everything from standard system tasks to
running the VM software!
Finally, spare a moment to check the Display settings. Default settings should
be fine but if there is an issue with the display you can toggle 3D acceleration.
Multiple monitors can be used and custom resolution set, but note that some
modes will clash with some desktops.
Click OK to confirm changes, then select the virtual machine and click the
Play button to begin.