0% found this document useful (0 votes)
49 views105 pages

CS3461-OS Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views105 pages

CS3461-OS Lab Record

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 105

P.T.

Lee Chengalvaraya Naicker


College of Engineering & Technology
(Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai)
Vallal P.T.Lee Chengalvaraya Naicker Nagar, Oovery, Kanchipuram – 631 502

Department of Computer Science and Engineering

Regulation - 2021

CS3461- Operating System Laboratory

RECORD

Name :
Reg. No :
Year/ Semester :
P.T.Lee Chengalvaraya Naicker
College of Engineering & Technology
(Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai)
Vallal P.T.Lee Chengalvaraya Naicker Nagar, Oovery,
Kanchipuram – 631 502.

Department of Computer Science and Engineering

BONAFIDE CERTIFICATE

RegNo:
Certified that this is a bonafide record of work done by the Candidate
Mr\Mrs. in CS3461-Operating
System Laboratory during for academic year .

Lab-in-charge Head of the Department

Submitted for the Practical Examination held on .

Internal Examiner External Examiner


INDEX

PAGE
EX.NO DATE NAME OF THE PROGRAM SIGN
NO

INSTALLATION OF WINDOWS OPERATING


1
SYSTEM

2A BASICS OF UNIX COMMANDS

SHELL PROGRAM TO CHECK THE GIVEN


2B
NUMBER IS EVEN OR ODD

SHELL PROGRAM TO CHECK THE GIVEN YEAR


2C
IS LEAP YEAR OR NOT

SHELL PROGRAM TO FIND THE FACTORIAL OF A


2D
NUMBER

2E SHELL PROGRAM TO SWAP THE TWO INTEGERS

PROGRAM FOR SYSTEM CALLS (OPENDIR,


3A
READDIR, CLOSEDIR)

PROGRAM FOR SYSTEM CALLS (FORK, GETPID,


3B
EXIT)

CPU SCHEDULING ALGORITHMS – FCFS


4A
SCHEDULING

CPU SCHEDULING ALGORITHMS – SJF


4B
SCHEDULING

CPU SCHEDULING ALGORITHMS – PRIORITY


4C
SCHEDULING

CPU SCHEDULING ALGORITHMS – ROUND


4D
ROBIN SCHEDULING
PAGE
EX.NO DATE NAME OF THE PROGRAM SIGN
NO

5 IPC USING SHARED MEMORY

PRODUCER CONSUMER PROBLEM


6
USINGSEMAPHORES

BANKERS ALGORITHM FOR


7
DEADLOCKAVOIDANCE

8 ALGORITHM FOR DEADLOCK


DETECTION

THREADING &
9
SYNCHRONIZATION
APPLICATIONS

PAGING TECHNIQUE OF
10
MEMORY
MANAGEMENT

MEMORY ALLOCATION METHODS FOR


11 A
FIXEDPARTITION -FIRST FIT

MEMORY ALLOCATION METHODS FOR


11 B
FIXEDPARTITION - WORST FIT

MEMORY ALLOCATION METHODS FOR


11 C
FIXEDPARTITION - BEST FIT

12 A PAGE REPLACEMENT ALGORITHMS- FIFO

12 B PAGE REPLACEMENT ALGORITHMS- LRU

12 C PAGE REPLACEMENT ALGORITHMS- LFU

FILE ORGANIZATION TECHNIQUE -


13 A
SINGLELEVEL DIRECTORY
PAGE
EX.NO DATE NAME OF THE PROGRAM SIGN
NO

FILE ORGANIZATION TECHNIQUE- TWO


13 B
LEVELDIRECTORY

14 A FILE ALLOCATION STRATEGIES SEQUENTIAL

14 B FILE ALLOCATION STRATEGIES- LINKED

14 C FILE ALLOCATION STRATEGIES- INDEXED

DISK SCHEDULING ALGORITHMS


15 A
–FIRST COME FIRST SERVE

DISK SCHEDULING ALGORITHMS


15 B
–SHORT SEEK TIME FIRST

DISK SCHEDULING ALGORITHMS


15 C
–SCAN SCHEDULING

DISK SCHEDULING ALGORITHMS


15 D
–LOOK SCHEDULING

INSTALLATION OF GUEST OPERATING


16
SYSTEMLIKE LINUX USING VMWARE
Ex No : 01
INSTALLATION OF WINDOWS OPERATING SYSTEM
Date :

Aim
To install the windows 10 operating System.

Procedure
Creating an Installation Disc or Drive

Connect a blank USB flash drive or insert a blank writable DVD. You can install Windows 10 by
creating a bootable USB flash drive or DVD that contains the Windows 10 installation files. You'll
need a USB flash drive that's at least 8GB, or any blank DVD to get started.

If you already have Windows 10 installed on the PC and just want to reinstall it, it'll be easiest to
reinstall it from within Windows 10 instead of creating installation media.

If you want to upgrade from Windows 7 or Windows 8.1, you won't need to create an installation disc
or drive. However, you will need to follow most of this method to start the upgrade.

Booting from Windows 10 Installation Media


If you created a flash drive, connect it to the PC on which you want to install Windows 10. If youmade
a DVD, insert it into the drive now.

Boot the PC into the BIOS. If your PC is not already set up to boot from your flash or optical drive,
rebooting from your installation media won't work. You'll need to make a quick change inyour BIOS
to change the boot order.

Reboot the PC and immediately start pressing (over and over again) the F12 key required by your PC
to enter "Setup," or the BIOS.

Go to the Boot tab. You'll use the arrow keys to select it.

The Boot tab may instead say Boot Options or Boot Order, depending on your computer's
manufacturer.

1
Select a device from which to boot. You have a couple of options here:For a

USB flash drive, select the Removable Devices option.

For a disc installation, select the CD-ROM Drive or Optical Drive option.

Press the + key until your boot option is first. Once either Removable Devices or CD-ROM Driveis
at the top of the list, your computer will select your choice as its default boot option.

On some computers, you'll instead press one of the function keys (e.g., F5 or the arrow keys tonavigate an
option up to the top of the menu.

Save your settings. You should see a key prompt (e.g., F10 at the bottom of the screen thatcorrelates to
"Save and Exit". Pressing it will save your settings and restart your computer.

2
Wait for your computer to restart. Once your computer finishes restarting, you'll see a window here
with your geographical data. You're now ready to begin setting up your Windows 10 installation.

3
Click Next when prompted. You can also change the options on this page (e.g., the setuplanguage)
before continuing if need be.

Click Install Now. It's in the middle of the window.

4
Enter your Windows 10 key, then click Next. If you don't have a Windows 10 key, instead click Skip
in the bottom-right corner of the screen.

If you've already installed Windows 10 on this PC and were signed in with your Microsoft account,
your key should be linked to your account. When prompted, just sign in with your Microsoft account
and Windows will locate your key.[4]

If you've changed hardware in the PC, such as replacing the motherboard, you can activate Windows
after installing by going to Settings > Update & Security > Activation > Troubleshoot >I changed
hardware on this device recently. Sign in with your Microsoft account when prompted, choose This is
the device I'm using right now, and then click Activate.

Follow the on-screen instructions to install Windows 10. You'll be asked to perform a few tasks, such
as connecting to Wi-Fi and choosing some preferences. Once the installation is complete, you'll have
a fresh new installation of Windows 10.

5
If you're upgrading from an earlier version of Windows, you'll be asked if you want to upgrade the
current operating system or do a custom install. If you choose Upgrade, you'll preserve existing apps
and files.

Result
Thus the windows 10 operating system was successfully installed.

6
Ex No : 2A
BASICS OF UNIX COMMANDS
Date :

Aim
To study about the basics of UNIX Commands.

UNIX:
It is a multi-user operating system. Developed at AT & T Bell Industries, USA in 1969.

Ken Thomson along with Dennis Ritchie developed it from MULTICS (Multiplexed
Information and Computing Service) OS. By1980, UNIX had been completely rewritten using C
language.

LINUX:
It is similar to UNIX, which is created by Linus Torualds. All UNIX commands works in
Linux. Linux is a open source software. The main feature of Linux is coexisting with other OS such as
windows and UNIX.

STRUCTURE OF A LINUX SYSTEM:


It consists of three parts. a)UNIX kernel b) Shells c) Tools and Applications

UNIX KERNEL:
Kernel is the core of the UNIX OS. It controls all tasks, schedule all Processes and carries out
all the functions of OS. Decides when one programs tops and another starts.

SHELL:
Shell is the command interpreter in the UNIX OS. It accepts command from the user and
analyses and interprets them.

UNIX COMMANDS

a) date –used to check the date and time

7
Syn:$date

b) cal –used to display the calendar


Syn:$cal 2 2009
c) echo –used to print the message on the screen.

Syn:$echo “text”
d) ls
–used to list the files.

Your files are kept in a directory.

Syn: $lsls–s
All files (include files with prefix)

ls–l Lodetai (provide file statistics)

ls–t Order by creation time

ls– u Sort by access time (or show when last accessed together with –l)ls–s

Order by size ls–r Reverse order

ls–f Mark directories with /,executable with* , symbolic links with @, local sockets with =,
named pipes(FIFOs)with

ls–s Show file size ls– h“ Human Readable”, show file size in Kilo Bytes & Mega Bytes (h can be
used together with –l or)

ls[a-m]*List all the files whose name begin with alphabets From „a‟ to „m‟ls[a]*List

all the files whose name begins with „a‟ or „A‟

Eg:$ls>my list Output of „ls‟ command is stored to disk file named „my list‟

e) lp –used to take printouts

8
Syn:$lp filename
f) man –used to provide manual help on every UNIX commands.

Syn:$man unix command


$man cat

g) who & whoami –it displays data about all users who have logged into the system currently.
The next command displays about current user only.

Syn: $who
$whoami

h) uptime –tells you how long the computer has been running since its last reboot or power-off.

Syn:$uptime
i) uname –it displays the system information such as hardware platform, system name and
processor, OS type.

Syn:$uname–a
j) hostname –displays and set system host name

Syn:$ hostname
k) bc –stands for „best calculator‟

9
FILE MANIPULATION COMMANDS
a) cat–this create, view and concatenate files.

Creation:
Syn:$cat>filenam

eViewing:

Syn:$cat filename
Add text to an existing file:

Syn:$cat>>file

name

Concatenate:
Syn:$cat file1 file2>file3

$cat file1 file2>>file3 (no over writing of file3)

b) grep–used to search a particular word or pattern related to that word from the file.

Syn:$grep search word

filenameEg:$grep anu

student
c) rm–deletes a file from the file system

Syn:$rm filename
d) touch–used to create a blank file.

Syn:$touch file names


e) cp–copies the files or

directories Syn:$cpsource file

destination file Eg:$cp student

stud
10
f) mv–to rename the file or directory

syn:$mv old file new file


Eg:$mv–i student studentlist(-i prompt when overwrite)

g) cut–it cuts or pickup a given number of character or fields of the file.

Syn:$cut<option><filename

Eg: $cut –c filename

$cut–c1-10emp

$cut–f 3,6emp

$ cut –f 3-6 emp

-c cutting columns

-f cutting fields

h) head–displays10 lines from the head(top)of a given file

Syn:$head

filename

Eg:$head

student
To display the top two lines:

Syn:$head-2student

i) tail–displays last 10 lines of the file

Syn:$tail
filename
Eg:$tail
student
To display the bottom two lines;
11
File–are used to assign or remove permission all

Examples: $chmod u-wx student


Removes write and execute permission for users

$ch modu+rw, g+rwstuden


Assigns read and write permission for users and groups

$chmodg=rwx student
Assigns absolute permission for groups of all read, write and execute permissionsk)wc

It counts the number of lines, words, character in a specified file(s) with the options as –l,-w,-c

Syn: $wc –l filename


$wc –w filename

$wc–c filename

RESULT

Thus the basics of UNIX Commands have been executed successfully.

12
Ex No : 2B PROGRAM- SHELL PROGRAM TO CHECK THE GIVEN
Date :
NUMBER ISEVEN OR ODD

echo "Enter the Number"

read n

r=`expr $n % 2`

if [ $r -eq 0 ]

then

echo "$n is Even number"

else

echo "$n is Odd number"fi

OUTPUT

RESULT
Thus the above shell program for check the given number is even or odd has been verifiedand
executed successfully.

13
Ex No : 2C PROGRAM- SHELL PROGRAM TO CHECK THE GIVEN
YEAR ISLEAP YEAR OR NOT
Date :

echo "Enter the year"

read y

b=`expr $y % 4`

if [ $b -eq 0 ]

then

echo "$y is a leap year"

else

echo "$y is not a leap year"fi

OUTPUT

RESULT

Thus the above shell program for check the given year is leap year or not has been verified andexecuted
successfully.

14
Ex No : 2D PROGRAM- SHELL PROGRAM TO FIND THE
FACTORIAL OF ANUMBER
Date :

echo "Enter a Number"

read n

i=`expr $n - 1`

p=1

while [ $i -ge 1 ]

do

n=`expr $n \* $i

` i=`expr $i - 1`

done

echo "The Factorial of the given Number is $n"

OUTPUT

RESULT

Thus the above shell program for factorial of a number has been verified and executed

successfully.

15
Ex No : 2E PROGRAM- SHELL PROGRAM TO SWAP THE TWO
INTEGERS
Date :

PROGRAM:

echo "Enter Two Numbers"

read a b

temp=$a

a=$b

b=$temp

echo "after swapping"

echo $a $b

OUTPUT

RESULT

Thus the above shell program for swapping of two integers has been verified and executed
successfully.

16
Ex No : 3A PROGRAM- SYSTEM CALLS (OPENDIR, READDIR, CLOSEDIR)

Date :

PROGRAM:
#include<stdio.h>
#include<dirent.h>
#include<stdlib.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[100];
DIR *dirp;
printf(“\n\n ENTER DIRECTORY NAME”);
scanf(“%s”, buff);
if((dirp=opendir(buff))==NULL)
{
printf(“The given directory does not exist”);exit(1);
}
while(dptr=readdir(dirp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}

17
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

18
Ex No : 3B PROGRAM- SYSTEM CALLS (FORK, GETPID, EXIT)

Date :

PROGRAM:
#include<stdio.h>

#include<unistd.h>

#include<stdlib.h>

int main()

int pid,pid1,pid2;

pid=fork();

if(pid==-1)

printf("ERROR IN PROCESS CREATION \n");

exit(1);

if(pid!=0)

{ pid1=getpid();

printf("\n the parent process ID is %d\n", pid1);

else

pid2=getpid();

printf("\n the child process ID is %d\n", pid2);

19
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

20
Ex No : 4A PROGRAM- FCFS SCHEDULING
Date :

PROGRAM:
#include<stdio.h>

void findWaitingTime(int processes[], int n,int bt[], int wt[])

wt[0] = 0;

for (int i = 1; i < n ; i++ )

wt[i] = bt[i-1] + wt[i-1] ;

void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[])

for (int i = 0; i < n ;

i++)tat[i] = bt[i] +

wt[i];

void findavgTime( int processes[], int n, int bt[])

int wt[n], tat[n], total_wt = 0, total_tat = 0; findWaitingTime(processes,

n, bt, wt); findTurnAroundTime(processes, n, bt, wt, tat);

printf("Processes Burst time Waiting time Turn around time\n");for

(int i=0; i<n; i++)

total_wt = total_wt + wt[i];

total_tat = total_tat + tat[i];

printf(" %d ",(i+1));

printf(" %d ", bt[i] );


printf(" %d",wt[i] );
21
printf(" %d\n",tat[i] );

int s=(float)total_wt / (float)n;

int t=(float)total_tat / (float)n;

printf("Average waiting time = %d",s);

printf("\n");

printf("Average turn around time = %d ",t);

int main()

int processes[] = { 1, 2, 3};

int n = sizeof processes / sizeof processes[0];

int burst_time[] = {10, 5, 8};

findavgTime(processes, n, burst_time); return

0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.
22
Ex No : 4B PROGRAM - SJF SCHEDULING

Date :

PROGRAM:

#include <stdio.h>

int main()

int A[100][4];

int i, j, n, total = 0, index, temp;

float avg_wt, avg_tat;

printf("Enter number of process: ");

scanf("%d", &n);

printf("Enter Burst Time:\n");

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

printf("P%d: ", i + 1);

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

A[i][0] = i + 1;

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

{index = i;

for (j = i + 1; j < n; j++)

if (A[j][1] <

A[index][1])index = j;

temp = A[i][1];

A[i][1] =

A[index][1];

A[index][1] = temp;

temp = A[i][0];
23
A[i][0] = A[index][0];

A[index][0] = temp;

A[0][2] = 0;

for (i = 1; i < n; i++)

{A[i][2] = 0;

for (j = 0; j < i;

j++)A[i][2] +=

A[j][1];

total += A[i][2];

avg_wt = (float)total / n;

total = 0;

printf("P BT WT

TAT\n");for (i = 0; i

< n; i++) {

A[i][3] = A[i][1] + A[i][2];

total += A[i][3];

printf("P%d %d %d %d\n", A[i][0],

A[i][1], A[i][2], A[i][3]);

avg_tat = (float)total / n;

printf("Average Waiting Time= %f", avg_wt);

printf("\nAverage Turnaround Time= %f", avg_tat);

24
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

25
Ex No : 4C PROGRAM - PRIORITY SCHEDULING

Date :

PROGRAM:

#include<stdio.h>

#include<stdlib.h>

typedef struct

int pno;

int pri;

int btime;

int wtime;

}sp;

int main()

int i,j,n=0;

int tbm=0,totwtime=0,totttime=0;sp

*p,t;

printf("\n PRIORITY SCHEDULING.\n");

printf("\n enter the no of process ........ \n");

scanf("%d",&n);

p=(sp*)malloc(sizeof(sp));

printf("enter the burst time and priority:\n");

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

printf("process%d:”,i+1);

scanf("%d%d",&p[i].btime,&p[i].pri);

p[i].pno=i+1;
26
p[i].wtime=0;
}

for(i=0;i<n-

1;i++)

for(j=i+1;j<n;j++

if(p[i].pri>p[j].pri)

t=p[i];

p[i]=p[j];

p[j]=t;

printf("\n process\tbursttime\twaiting time\tturnaround time\n");

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

totwtime+=p[i].wtime=tbm;

tbm+=p[i].btime;

printf("\n%d\t\t%d",p[i].pno,p[i].btime);

printf("\t\t%d\t\t%d",p[i].wtime,p[i].wtime+p[i].btime);

totttime=tbm+totwtime;

printf("\n total waiting time:%d",totwtime);

printf("\n average waiting time:%f",(float)totwtime/n);

printf("\n total turnaround time:%d",totttime); printf("\n

avg turnaround time:%f",(float)totttime/n);

27
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

28
Ex No : 4D PROGRAM - ROUND ROBIN SCHEDULING

Date :

PROGRAM:
#include<stdio.h>

#include<stdlib.h>

struct rr

int pno,btime,sbtime,wtime,lst;

}p[10];

int main()

int pp=-1,ts,flag=0,count=0,ptm=0,i,n,twt=0,totttime=0;

printf("\n round robin scheduling ................");

printf("enter no of processes:");

scanf("%d",&n);

printf("enter the time slice:");

scanf("%d",&ts); printf("enter

the burst time");

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

printf("\n process%d\t",i+1);

scanf("%d",&p[i].btime);

p[i].wtime=p[i].lst=0;

p[i].pno=i+1;

p[i].sbtime=p[i].btime;

printf("scheduling .... \n");

29
do
{

flag=0;

for(i=0;i<n;i++

count=p[i].btime;

if(count>0)

flag=-1;

count=(count>=ts)?ts:count;

printf("\n process %d",p[i].pno);

printf("from%d",ptm);

ptm+=count; printf("to%d",ptm);

p[i].btime-=count;

if(pp!=i)

pp=i;

p[i].wtime+=ptm-p[i].lst-count;

p[i].lst=ptm;

}while(count>0);

30
OUTPUT

RESULT
Thus the above program has been verified and executed successfully.

31
Ex No : 5 PROGRAM- IPC USING SHARED MEMORY
Date :

PROGRAM:
#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<string.h>

#include<sys/ipc.h>

#include<sys/shm.h>

#include<sys/types.h>

#define SEGSIZE 100

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

int shmid,cntr;

key_t key; char

*segptr;

char buff[]="poooda ....... ";

key=ftok(".",'s');

if((shmid=shmget(key, SEGSIZE, IPC_CREAT | IPC_EXCL | 0666))== -1)

if((shmid=shmget(key,SEGSIZE,0))==-1)

perror("shmget");

exit(1);

Else
{
32
printf("Creating a new shared memory seg \n");

printf("SHMID:%d",shmid);}

system("ipcs –m");

if((segptr=(char*)shmat(shmid,0,0))==(char*)-1)

perror("shmat");

exit(1);

printf("Writing data to shared memory...\n");

strcpy(segptr,buff);

printf("DONE\n");

printf("Reading data from shared memory...\n");

printf("DATA:-%s\n",segptr);

printf("DONE\n");

printf("Removing shared memory Segment...\n");

if(shmctl(shmid,IPC_RMID,0)== -1)

printf("Can’t Remove Shared memory Segment...\n");

else

printf("Removed Successfully");

33
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

34
Ex No : 6 PROGRAM- PRODUCER CONSUMER PROBLEM
USINGSEMAPHORES
Date :

PROGRAM:
#include<stdio.h>

int mutex=1,full=0,empty=3,x=0;

void main()

int n;

void producer();

void consumer();

int wait(int);

int signal(int);

printf("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");

while(1) {

printf("\nENTER YOUR

CHOICE\n");scanf("%d",&n);

switch(n)

{ case 1:

if((mutex==1)&&(empty!=0))

producer();

else

printf("BUFFER IS FULL");

break;

case 2:

if((mutex==1)&&(full!=0)

)consumer();

else

35
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("\nproducer produces the item%d",x);

mutex=signal(mutex); }

void consumer() {

mutex=wait(mutex);

full=wait(full);

empty=signal(empty);

printf("\n consumer consumes item%d",x);x-

-;

mutex=signal(mutex);
}

36
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

37
Ex No : 7 BANKERS ALGORITHM FOR DEADLOCK
AVOIDANCE
Date :

PROGRAM:
#include<stdio.h>

int max[100][100];

int alloc[100][100];

int need[100][100];

int avail[100];

int n,r;

void input();

void show();

void cal();

int main()

int i,j;

printf("********** Baner's Algo ************\n");

input();

show();

cal();

return 0;

void input()

int i,j;

printf("Enter the no of Processes\t");

scanf("%d",&n);

printf("Enter the no of resources instances\t");


38
scanf("%d",&r);
printf("Enter the Max Matrix\n");for(i=0;i<n;i++)
{

for(j=0;j<r;j++)

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

printf("Enter the Allocation Matrix\n");

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

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

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

printf("Enter the available Resources\n");

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

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

void show()

int i,j;

printf("Process\t Allocation\t Max\t Available\t");

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

printf("\nP%d\t ",i+1);

39
for(j=0;j<r;j++)

printf("%d ",alloc[i][j]);

printf("\t");

for(j=0;j<r;j++

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

printf("\t");

if(i==0) {

for(j=0;j<r;j++

printf("%d ",avail[j]);

void cal()

int finish[100],temp,need[100][100],flag=1,k,c1=0;int

safe[100];

int i,j;

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

{finish[i]=0; }

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

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

40
need[i][j]=max[i][j]-alloc[i][j];}

printf("\n");

while(flag)

flag=0;

for(i=0;i<n;i++

int c=0;

for(j=0;j<r;j++

if((finish[i]==0)&&(need[i][j]<=avail[j]))

c++

if(c==r)

for(k=0;k<r;k++) {

avail[k]+=alloc[i][j]

;finish[i]=1;

flag=1; }

printf("P%d->",i);

if(finish[i]==1)

i=n;

}}}}}}

41
for(i=0;i<n;i++){

if(finish[i]==1)

c1++;

else

printf("P%d->",i);

if(c1==n)

{printf("\n The system is in safe state");

else

printf("\n Process are in dead lock");printf("\n

System is in unsafe state");

42
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

43
Ex No : 8
PROGRAM- ALGORITHM FOR DEADLOCK DETECTION
Date :

PROGRAM:
#include<stdio.h>

int max[100][100];

int alloc[100][100];

int need[100][100];

int avail[100];

int n,r;

void input();

void show();

void cal();

int main()

int i,j;

printf("********** Deadlock Detection Algo ************\n");

input();

show();

cal();

return 0;

void input ()

int i , j;

printf ("Enter the no of Processes\t");

scanf ("%d", &n);

printf ("Enter the no of resource instances \t");

44
scanf ("%d", &r);
printf ("Enter the Max Matrix \n");for (i=0 ; i<n;i++)
{

for (j=0; j<r; j++)

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

printf("Enter the Allocation Matrix \n");

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

for(j=0; j<r; j++)

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

printf("Enter the available Resources \n");for

(j=0; j < r ; j++)

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

}}

void show ()

int i,j;

printf("Process \t Allocation \t Max \t Available \t");


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

printf(" \nP%d \t ",i+1);

for(j=0;j<r;j++)

{
45
printf ("%d ",alloc[i][j]);

printf (" \t");

for(j=0;j<r;j++

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

printf(" \t");

if(i==0)

for(j=0;j<r;j++)

printf("%d ",avail[j]);

void cal ()

int finish[100],temp,need[100][100],flag=1,k,cl=0;int

dead[100];

int safe[100];

int

i,j;for(i=0;i<n

;i++)

finish[i]=0;

46
for(i=0;i<n;i++)

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

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

}}

while(flag)

flag=0;

for(i=0;i<n;i++

int c=0;

for(j=0;j<r;j++

if((finish[i]==0)&&(need[i][j]<=avail[j]))

c++

if(c==r)

for(k=0;k<r;k++)

avail[k]+=alloc[i][j]

;finish[i]=1;

flag=1;

if(finish[i]==1)
47
{

i=n;

}}}}

}}

j=0;

flag=0;

for(i=0;i<n;i++

if(finish[i]==0)

dead[j]=i;

j++;

flag=1;

if(flag==1)

printf("\n\nSystem is in Deadlock and the Deadlock process are\n");

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

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

Else
{
printf("\nNo Deadlock Occur");

48
}

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

49
Ex No : 9 THREADING & SYNCHRONIZATIONAPPLICATIONS
Date :

PROGRAM:
#include<stdio.h>

#include<string.h>

#include<pthread.h>

#include<stdlib.h>

#include<unistd.h>

pthread_t tid[2];

void* doSomeThing(void *arg)

unsigned long i = 0; pthread_t

id = pthread_self();

if(pthread_equal(id ,tid[0]))

printf("\n First thread processing\n");

else

printf("\n Second thread processing\n");

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

return NULL;

int main(void)

int i = 0;

50
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));else

printf("\n Thread created successfully\n");

i++;

sleep(5);

return 0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

51
Ex No : 10 PAGING TECHNIQUE OF MEMORY
MANAGEMENT
Date :

PROGRAM:
#include<stdio.h>

#include<string.h>

#include<pthread.h>

#include<stdlib.h>

#include<unistd.h>

pthread_t tid[2];

int counter;

pthread_mutex_t lock;

void* doSomeThing(void *arg)

pthread_mutex_lock(&lock);

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);pthread_mutex_unlock(&lock);

return NULL;

int main(void)

int i = 0;

int err;

if (pthread_mutex_init(&lock, NULL) != 0)
{
printf("\n mutex init failed\n");return 1;
}
52
while(i < 2)
{

err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);

if (err != 0)

printf("\ncan't create thread :[%s]", strerror(err));i++;

pthread_join(tid[0], NULL);

pthread_join(tid[1], NULL);

pthread_mutex_destroy(&lock);

return 0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

53
Ex No : 11A MEMORY ALLOCATION METHODS FOR FIXED
PARTITION -FIRST FIT
Date :

PROGRAM:
#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];

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++)

54
{

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’,i,f *i+,ff *i+,b *ff *i++,frag *i+);getch();

55
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

56
Ex No : 11B MEMORY ALLOCATION METHODS FOR FIXED
PARTITION - WORST FIT
Date :

PROGRAM:
#include<stdio.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++)
{

57
for(j=1;j<=nb;j++)

{
if(bf [j]!=1)

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();

58
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

59
Ex No : 11C MEMORY ALLOCATION METHODS FOR FIXED
PARTITION - BEST FIT
Date :

PROGRAM:

#include<stdio.h>

#define max 25

void main()

int frag[max],b[max],f[max],I,j,nb,nf,temp,lowest=10000;

static int bf[max],ff[max];

clrscr();

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+);

}
60
for(i=1;i<=nf;i++)
{

for(j=1;j<=nb;j++)
{

if(bf[j]!=1)

temp=b[j] – f[j];

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_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();

61
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

62
Ex No : 12A PAGE REPLACEMENT ALGORITHMS- FIFO
Date :

PROGRAM:
#include<stdio.h>

int main()

int incomingStream[] = {4, 1, 2, 4, 5};

int pageFaults = 0;

int frames = 3;

int m, n, s, pages;

pages = sizeof(incomingStream)/sizeof(incomingStream[0]);

printf("Incoming \t Frame 1 \t Frame 2 \t Frame 3");

int temp[frames];

for(m = 0; m < frames; m++)

temp[m] = -1;

for(m = 0; m < pages; m++)

s = 0;

for(n = 0; n < frames; n++)

if(incomingStream[m] == temp[n])

s++;

pageFaults--;

}
63
}
pageFaults++;

if((pageFaults <= frames) && (s == 0))

{
temp[m] = incomingStream[m];

else if(s == 0)

temp[(pageFaults - 1) % frames] = incomingStream[m];

printf("\n");

printf("%d\t\t\t",incomingStream[m]);

for(n = 0; n < frames; n++)

if(temp[n] != -1)

printf(" %d\t\t\t", temp[n]);

else

printf(" - \t\t\t");

printf("\nTotal Page Faults:\t%d\n", pageFaults);

return 0;

64
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

65
Ex No : 12B PAGE REPLACEMENT ALGORITHMS- LRU
Date :

PROGRAM:
#include<stdio.h>

int main()

int m, n, position, k, l;

int a = 0, b = 0, page_fault = 0;

int total_frames = 3;

int frames[total_frames];

int temp[total_frames];

int pages[] = {1, 2, 3, 2, 1, 5, 2, 1, 6, 2, 5, 6, 3, 1, 3, 6, 1, 2, 4, 3};

int total_pages = sizeof(pages)/sizeof(pages[0]);

for(m = 0; m < total_frames; m++)

frames[m] = -1;

for(n = 0; n < total_pages; n++)

printf("%d: ", pages[n]);

a = 0, b = 0;

for(m = 0; m < total_frames; m++)

if(frames[m] == pages[n])

a = 1;

b = 1;
break;
66
}

if(a == 0)
{

for(m = 0; m < total_frames; m++)

if(frames[m] == -1)

frames[m] = pages[n];

b = 1;

page_fault++;

break;

if(b == 0)

for(m = 0; m < total_frames; m++)

temp[m] = 0;

for(k = n - 1, l = 1; l <= total_frames - 1; l++, k--)

for(m = 0; m < total_frames; m++)

if(frames[m] == pages[k])
{
temp[m] = 1;

67
}

for(m = 0; m < total_frames; m++)


{

if(temp[m] == 0)

position = m;

frames[position] = pages[n];

page_fault++;

for(m = 0; m < total_frames; m++)

printf("%d\t", frames[m]);

printf("\n");

printf("\nTotal Number of Page Faults:\t%d\n", page_fault);

return 0;

68
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

69
Ex No : 12C PAGE REPLACEMENT ALGORITHMS- LFU
Date :

PROGRAM:
#include<stdio.h>

int main()

int f,p;

int pages[50],frame[10],hit=0,count[50],time[50];int

i,j,page,flag,least,minTime,temp; printf("Enter no

of frames : ");

scanf("%d",&f);

printf("Enter no of pages : ");

scanf("%d",&p);

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

frame[i]=-1;

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

count[i]=0;

printf("Enter page no : \n");

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

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

printf("\n");
for(i=0;i<p;i++)
70
{
count[pages[i]]++;time[pages[i]]=i; flag=1; least=frame[0]; for(j=0;j<f;j++)
{

if(frame[j]==-1 || frame[j]==pages[i])
{

if(frame[j]!=-1)

hit++;

flag=0;

frame[j]=pages[i];

break;

if(count[least]>count[frame[j]])

least=frame[j]; }}

if(flag) {

minTime=50;

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

if(count[frame[j]]==count[least] && time[frame[j]]<minTime)

temp=j;
minTime=time[frame[j]];
}}

count[frame[temp]]=0;

frame[temp]=pages[i];

for(j=0;j<f;j++)

printf("%d ",frame[j]);

71
}

printf("\n");}

printf("Page hit = %d",hit);

return 0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

72
Ex No : 13A FILE ORGANIZATION TECHNIQUE -SINGLE
LEVEL DIRECTORY
Date :

PROGRAM:
import os

def create_file(filename):

if not os.path.exists(filename):

with open(filename, 'w') as f:

f.write("This is a new file.")

def main():

directory = input("Enter directory name: ")if

not os.path.exists(directory):

os.makedirs(directory)

os.chdir(directory)

while True:

command = input("Enter command (create, list, quit): ")if

command == "create":

filename = input("Enter file name: ")

create_file(filename)

elif command == "list":

print(os.listdir())

elif command == "quit":

break

else:

print("Invalid command.")

if name == " main ":

main()

73
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

74
Ex No : 13B FILE ORGANIZATION TECHNIQUE- TWO LEVEL
DIRECTORY
Date :

PROGRAM:
import os

# Define the top-level directory name

top_level_dir = "Projects"

# Create the top-level directory

if not os.path.exists(top_level_dir):

os.mkdir(top_level_dir)

# Define the subdirectories

subdirs = ["Project1", "Project2", "Project3"]

# Create the subdirectories within the top-level directoryfor

subdir in subdirs:

subdir_path = os.path.join(top_level_dir, subdir)if

not os.path.exists(subdir_path):

os.mkdir(subdir_path)

# Define some example files

files = ["file1.txt", "file2.txt", "file3.txt"]

# Store the files in the appropriate subdirectoriesfor

i, subdir in enumerate(subdirs):

subdir_path = os.path.join(top_level_dir, subdir)for

file in files:

75
file_path = os.path.join(subdir_path, file)with

open(file_path, "w") as f:

f.write(f"This is {file} in {subdir} of {top_level_dir}.")

print(f"Created file: {file_path}")

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

76
Ex No : 14A FILE ALLOCATION STRATEGIES- SEQUENTIAL
Date :

PROGRAM:
#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

void 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))

77
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;

getch();

78
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

79
Ex No : 14B FILE ALLOCATION STRATEGIES- LINKED
Date :

PROGRAM:
#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main()

int f[50], p,i, st, len, j, c, k, a;

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

f[i]=0;

printf("Enter how many blocks already allocated: ");

scanf("%d",&p);

printf("Enter blocks already allocated: ");

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

scanf("%d",&a);

f[a]=1;

x: printf("Enter index starting block and length: ");

scanf("%d%d", &st,&len);

k=len;

if(f[st]==0

for(j=st;j<(st+k);j++)

80
if(f[j]==0)
{

f[j]=1;

printf("%d ------- >%d\n",j,f[j]);

else

printf("%d Block is already allocated \n",j);

k++;

else

printf("%d starting block is already allocated \n",st); printf("Do

you want to enter more file(Yes - 1/No - 0)");scanf("%d", &c);

if(c==1

)goto x;

else

exit(0);

getch();

81
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

82
Ex No : 14C FILE ALLOCATION STRATEGIES- INDEXED
Date :

PROGRAM:
#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void 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++

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

83
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);

getch();}

84
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

85
Ex No : 15A PROGRAM- FCFS SCHEDULING
Date :

PROGRAM:
#include<stdio.h>

#include<stdlib.h>

int 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);

// logic for FCFS disk scheduling

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

TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);

initial=RQ[i];

printf("Total head moment is %d",TotalHeadMoment);

return 0;

86
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

87
Ex No : 15B PROGRAM- SSTF SCHEDULING
Date :

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);

// logic for sstf disk scheduling

/* loop will execute until all process is completed*/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;

88
}

TotalHeadMoment=TotalHeadMoment+min;

initial=RQ[index];

// 1000 is for max

// you can use any number

RQ[index]=1000;

count++;

printf("Total head movement is %d",TotalHeadMoment);

return 0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

89
Ex No : 15C PROGRAM –SCAN SCHEDULING
Date :

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 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

])

90
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

91
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];

92
printf("Total head movement is %d",TotalHeadMoment);

return 0;

OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

93
Ex No : 15D PROGRAM –LOOK SCHEDULING
Date :

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 look 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

])

94
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];

for(i=index-1;i>=0;i--)

95
{

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];

for(i=index;i<n;i++)

TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);

initial=RQ[i];

printf("Total head movement is %d",TotalHeadMoment);

return 0;

96
OUTPUT

RESULT

Thus the above program has been verified and executed successfully.

97
Ex No : 16
INSTALLATION OF GUEST OPERATING SYSTEM LIKE LINUX USING VMWARE
Date :

AIM
To install the Guest OS like linux using VMware workstation.

PROCEDURE
What is a guest operating system (guest OS)?

A guest operating system is the operating system installed on either a virtual machine (VM) or
partitioned disk. It is usually different from the host operating system. Simply put, a host OS runs on
hardware, while a guest OS runs on a VM.

Virtualization and guest OS


Virtualization technology allows a single computer to run more than one OS at the same time. Thus, a
single physical machine can be configured as multiple VMs. These VMs are isolated sections of
hardware with storage, processing, memory and network capacity. Virtualization also allows resource
sharing between the host OS and guest OS.

Process to install guest OS from ISO images in VMware Workstation:To

install the OS from an ISO image in a virtual machine:

1. Save the ISO image file in any location accessible to your host. For

example:Windows: C:\Temp or %TEMP%

Linux: /tmp or /usr/tmp

Note: For best performance, place this image on the host computer's hard drive. However, to make the
ISO image accessible to multiple users, you can also place the ISO image on a networkshare drive
(Windows) or exported filesystem (Linux). If your OS install spans multiple discs, youneed to use an
ISO image of each disc and place them all of them in a location accessible to the host.

2. Create a new virtual machine. Go to File > New > Virtual Machine.

3. Select Typical to accept Workstation's recommendations for various settings (such as


processors, RAM, and disk controller type). Select Custom if you want to select these options
yourself.

98
4. On the Guest Operating System Installation screen, when prompted where to install
from,select Installer disc image file (iso).

5. Click Browse, and navigate to the location where you saved the ISO image file.

6. Click Next, and proceed through the new virtual machine wizard.

7. Before you click Finish, to create the virtual machine, deselect Power on this virtual
machineafter creation.

8. Edit the virtual machine settings so that its virtual CD/DVD device is configured to
use theISO image rather than the physical CD/DVD drive:

i.Select the tab for the virtual machine you just created.

ii.Click Edit virtual machine settings.

iii.On the Hardware tab, select the CD/DVD

drive.iv.On the right side:

a.Select Connect at power

on.b.Select Use ISO

image file.

c.Click Browse and navigate to where you saved the ISO image file.

v. Click OK.

9. Power on the virtual machine.

The virtual machine boots from the ISO image, which contains the installation software for your
guest OS. Follow the installation procedure for your guest OS.

Note: If the guest OS asks for the second CD/DVD, repeat step 8 to point the virtual CD/DVD
device to the second ISO image.

When you are finished installing the guest OS, you can edit the virtual machine settings so that it
is once more set to use the host computer's physical drive. You do not need to leave the drive set
to connect at power on.

RESULT
Thus the guest OS like Linux using VMware workstation was successfully installed.

99
100

You might also like