0% found this document useful (0 votes)
21 views94 pages

Os Lab Manual Final PDF

The document provides detailed instructions on installing the Windows 11 operating system, including system requirements and step-by-step procedures for installation. It also covers basic UNIX commands, shell programming for number checking and multiplication tables, and process management using system calls like fork(), getpid(), and wait(). The results indicate successful execution and verification of all tasks outlined in the document.

Uploaded by

madhanraj143nve
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)
21 views94 pages

Os Lab Manual Final PDF

The document provides detailed instructions on installing the Windows 11 operating system, including system requirements and step-by-step procedures for installation. It also covers basic UNIX commands, shell programming for number checking and multiplication tables, and process management using system calls like fork(), getpid(), and wait(). The results indicate successful execution and verification of all tasks outlined in the document.

Uploaded by

madhanraj143nve
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/ 94

Ex no : 1 INSTALLATION OF WINDOWS OPERATING SYSTEM(WINDOWS-11)

Date :

AIM:

To study on how to install windows operating system (windows-11).

SYSTEM REQUIREMENTS FOR INSTALLING WINDOWS-11 OS:

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:

The windows os is installed successfully.


Ex no : 2.a) ILLUSTRATE UNIX COMMANDS

Date :

AIM:
To study the basic commands in unix.
COMMON UNIX COMMANDS:

Command Action

cat <file> Print contents of file in the command window

cd
<directory> Change directories

cp
<file><file2> Copy the contents of file into file2

History List history of all commands issued at system prompt

Ls List the files and subdirectories in a directory

List the difference between files and directories--directories have a slash


ls -F (/)

ls –l List files with status/detail information

List file information in long format, sorted by time with newest files or newly
ls -lt changed files
appearing first

ls -a List all the files in a directory including dot files

fs lq Lists AFS quota, space used, percentage used

fs q Lists percentage of quota used

mkdir Make a directory


<directory>
mv
<file><file2>
Move file to file 2

pwd Print the pathname of the current directory

rm <file> Remove or delete files

rmdir
<directory> Remove directory

Ctrl + C To negate a command that you have entered.

COMMAND EXAMPLES:

Navigating the File System (cd command)


directories.
To list ALL Type ls -a and press
files, Enter.
including
Dot
files.

Recursive Type ls -R and press


file Enter. Lists the files in the current
directory as well as those in
Listing
the subdirectories.

Create
Directory (mkdir)

Function Command Example Notes

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)

Function Command Example Notes

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.

To make a copy of a file


named
"resume" in the private
directory.

To copy a Type cp<path> / cp ~juser/notes


file <file><path> sample/notes.joe
into another
/ <file> and press Enter.
user's
account.
To copy a file named
"notes" from
your friend Joe's account
into
your sample directory
and name the file
notes.joe.

Move Files or Directories (mv)

Function Command Example Notes

To move a Type mv<file><file2> mv notes.joe notes.working The difference between mv


file and and
press Enter. cp is that cp places a copy of
to a new file
in the
To move a file named file in a new location
the same "notes.joe" to a file without disturbing the
directory named original copy. The
(i.e., "notes.working."In
rename a this case, mv is simply mv commands deletes the
file). renaming file
from its old location after
saving
it in the new location.
the file.

To move a Type mv<file><path>/ The mv command is also


file <file> mv notes public/notes used to
to a new file
in and press Enter. move directories.
a different To move a file named
"notes"
Directory from your home directory
into your public directory,
while IN your home
directory.

Remove a
File (rm)

Function Command Example Notes

To remove Type rm<file> and press


a Enter. rm notes.working
file. To remove the file named
"notes.working"

Prompt Type rm -i and press To invoke a prompt


remove Enter. before removing a file;
waits for a "Y" or
"N" response.

Remove a
Directory (rmdir)

Function Command Example Notes

To remove Type rmdir<directory Because the "sample"


a name> cd [Enter] directory
directory rmdir sample is in a subdirectory of your
and press Enter. home
(that
does not directory, you must first
move to
contain
files). To remove a directory your home directory (cd).
named
subdirectory

RESULT:

The unix commands are executed successfully in the terminal and outputs are verified.
Ex no : 2.b) SHELL PROGRAMMING

Date :

i) NUMBER CHECKING USING SHELL PROGRAM

AIM:

To check the number using shell program.

ALGORITHM:

1. Enter the input in the num variable.


2. Check the condition of for loop
3. Check the condition of if statement and if the condition is true print even no else print odd on
4. Repeat step 2 until condition becomes false.

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:

echo "which table do you want?"


read n
for (( i=1; i<=10; i++ ))
do
echo "$i * $n = $((i*n))"
done

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 :

i) PROGRAM USING SYSTEM CALL fork()

AIM :
To execute fork() system call.

ALGORITHM :

1. Import the necessary preprocessor directives

2. Define the main function

3. Check whether pid is less than 0 if so print fork failed

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:

Thus the fork() system call is executed and verified successfully


ii) PROGRAM USING SYSTEM CALLS getpid() & getppid()

AIM :
To execute the getpid() and getppid() system calls

ALGORITHM :

1. Import the necessary preprocessor directives


2. Check the value of pid whether -1 and print fork failed
3. Otherwise check the value of pid whether equal to 0 and print child process is under execution else print
parent process is under execution.

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 :

1. Import necessary preprocessor directives.


2. Check the value of pid if it is -1 print fork failed
3. Else check equal to 0 if so, print the process id
4. Else call wait() and print parent ends and call exit() system call

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

i) FCFS (FIRST COME FIRST SERVE) CPU SCHEDULING

AIM:
To implement FCFS CPU scheduling algorithm

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Calculate and print total turn around time, waiting time and average turn around time and waiting time

PROGRAM: (FCFS Scheduling)

#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;
}

OUTPUT: (FCFS Scheduling Algorithm)

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:

1.Import necessary preprocessor directives


2.Declare the variables
3. Calculate and print total turn around time, waiting time and average turn around time and waiting time

PROGRAM: (SJF Scheduling)

#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]);
}

OUTPUT: (SJF Scheduling Algorithm)

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:

1.Import necessary preprocessor directives


2.Declare the variables
3. Calculate and print total turn around time, waiting time and average turn around time and waiting time

PROGRAM: (Priority Scheduling)


#include<stdio.h>
int p[30],bt[30],tot_tat=0,pr[30],wt[30],n,tot_wt=0,tat[30],pr_wt=0,pr_tat=0;
float avt,avg_tat,avg_wt;
void main(){
int i;
printf("\n enterthe no of proccessors\n");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("\n enter the burst time and priority of process[%d]:\n",i+1);
scanf("%d%d",&bt[i],&pr[i]);
p[i]=i;
}
sort();
wt_tat(&pr_tat,&pr_wt);
printf("\n\n total turn around time:%d",pr_tat);
printf("\n average turn ariund time :%d",pr_tat/n);
printf("\n tatol waiting time:%d",pr_wt);
printf("\n total avg waiting time:%d",pr_wt/n);
}
int sort(){
int t,i,j,t2,t1;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(pr[i]>pr[j]){
swap(&bt[j],&bt[i]); swap(&p[j],&p[i]); swap(&pr[j],&pr[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 priority \n turn around time \t waiting
time");
for(i=0;i<n;i++)
printf("\n process[%d] \t\t%d\t %d\t %d \t%d",p[i]+1,bt[i],pr[i],tat[i],wt[i]);
return 0;
}
OUTPUT: (Priority Scheduling 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:

1.Import necessary preprocessor directives


2.Declare the variables
3. Calculate and print total turn around time, waiting time and average turn around time and waiting time

PROGRAM: (Round Robin Algorithm)


#include<stdio.h>
int true = 0; int false=-1; int
tbt[30],bt[30],tat[30],n=0,wt[30],qt=0,tqt=0,time=0,lmore,t_tat=0,t_wt=0;
void main(){ int i,j; printf("enter the no of process:"); scanf("%d",&n);
printf("\n enter quantum time:"); scanf("%d",&qt); for(i=0;i<n;i++){
printf("enter burst time of process[%d]:",i+1); scanf("%d",&bt[i]);
tbt[i]=bt[i];
wt[i]=tat[i]=0;
}
lmore=true;
while(lmore==true){
lmore=false;
for(i=0;i<n;i++){
if(bt[i]!=0)
wt[i]=wt[i]+(time -tat[i]);
tqt=1;
while(tqt<=qt && bt[i]!=0){
lmore=true;
bt[i]=bt[i]-1;
tqt++;
time++;
tat[i]=time;
}
}
}
printf("\n processes \tbursttime\tturnaround time\twaitingtime\n");
for(i=0;i<n;i++)
{
printf("\nprocess %d\t%d\t%d\t%d",i+1, tbt[i], tat[i], wt[i]);
t_tat =t_tat+tat[i];
t_wt =t_wt+wt[i];
}
printf("\n total turn around time:%d",t_tat);
printf("\n average turn around time : %d",t_tat/n);
printf("\n total waiting time :%d",t_wt);
printf("\n average waiting time ;%d",t_wt/n);
}

OUTPUT: (Round Robin Scheduling 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:

1. Import necessary preprocessor directives


2. Read key for shared memory , data to share
3. Print stored data

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:

1. Import necessary preprocessor directives


2. Declare the variables
3. Thread t1 and t2 will be created and goes to sleep for 2 milliseconds and resumes

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:

To implement Bankers algorithm for deadlock avoidance

ALGORITHM:

1. Import the necessary preprocessor directives


2. Declare the variables
3. Read the number of resources allocated, available and maximum number of resources and the requested
needed
4. Print whether deadlock occurs or not.

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:

To implement Deadlock Detection algorithm.

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Read claim matrix, allocation matrix, resource vector and availability vector
4. Print the processes causing deadlock

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:

Enter total no. of processes: 4


Enter total no. of resources: 5
Enter claim (Max. Need) matrix:
01001
00101
00001
10101
Enter allocation matrix :
10110
11000
00010
00000
Enter resource vector (Total resources):
21121
Enter availability vector (available resources):
00001
deadlock causing processes are : 2 3

RESULT:

Thus the program for deadlock detection is executed and verified successfully.
Ex no : 9 IMPLEMENTATION OF THREADING

Date :

AIM:
To implement threading

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Print Jobs starting and ending

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:

Thus the program for threading is executed and verified successfully.


Ex no : 10 IMPLEMENTATION OF PAGING TECHNIQUE

Date :

AIM:
To implement paging technique

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Read the size of physical memory, frame, frame available, page number and offset
4. Print the Physical address

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

Date : (FIRST FIT,WORST FIT & BEST FIT)

i) FIRST FIT

AIM:

To implement First Fit memory allocation method

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Read number of blocks, number of files and size of files
4. Print file number, file size, block number, block size and fragment

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:

To implement Worst Fit memory allocation method.

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Read number of blocks, number of files and size of files
4. Print file number, file size, block number, block size and fragment

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:

To implement Best Fit memory allocation method

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the variables
3. Read number of blocks, number of files and size of files
4. Print file number, file size, block number, block size and fragment

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:

To implement FIFO page replacement algorithm

ALGORITHM:

1. Import necessary preprocessor directives


2. Read number of pages, page number, number of frames
3. Print number of page faults

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:

To implement LRU page replacement algorithm

ALGORITHM :

1. Import necessary preprocessor directives


2. Read number of pages, page number, number of frames
3. Print number of page faults

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:

To implement OPTIMAL page replacement algorithm

ALGORITHM :

1. Import necessary preprocessor directives


2. Read number of pages, page number, number of frames
3. Print number of page faults

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 :

i)SINGLE LEVEL DIRECTORY

AIM:

To implement single level directory file organization technique

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the structure
3 . Read choice and name of the file
4 . If the choice is 1 create a file
5 . If the choice is 2 delete a file
6 . If the choice is 3 search for a file
7.
If the choice is 4 display all the files
8.
If the choice is 5 exit the program

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:

lab-3-27@GCECSE-27:~$ gcc -o singleex13 singleex13.c


lab-3-27@GCECSE-27:~$ ./singleex13
Enter name of directory -- cse
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 1
Enter the name of the file -- A
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 1
Enter the name of the file -- B
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 1
Enter the name of the file -- C
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 4
The Files are -- A B C
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 3
Enter the name of the file -- A
File A is found
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 3
Enter the name of the file -- D
File D not found
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 2
Enter the name of the file -- C
File C is deleted
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit
Enter your choice -- 5
lab-3-27@GCECSE-27:~$

RESULT:

Thus the program single level directory file organization technique is executed successfully and output is
ver if ied.
ii) TWO LEVEL DIRECTORY

AIM:

To implement single level directory file organization technique

ALGORITHM:

1. Import necessary preprocessor directives


2. Declare the structure
3 . Read choice and name of the file
4 . If the choice is 1 create a file
5 . If the choice is 2 delete a file
6.
If the choice is 3 search for a file
7.
If the choice is 4 display all the files
8. If the choice is 5 exit the program

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:

ab-3-27@GCECSE-27:~$ gcc -o ex13twolevel ex13twolevel.c


lab-3-27@GCECSE-27:~$ ./ex13twolevel
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Enter name of directory -- DIR1
Directory created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Enter name of directory -- DIR2
Directory created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory -- DIR1
Enter name of the file -- A1
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory -- DIR1
Enter name of the file -- A2
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory -- DIR2
Enter name of the file -- B1
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory -- DIR2
Enter name of the file -- B2
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 5
Directory Files
DIR1 A1 A2
DIR2 B1 B2
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 4
Enter name of the directory -- DIR1
Enter the name of the file -- A1
File A1 is found
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 3
Enter name of the directory -- DIR2
Enter name of the file -- B2
File B2 is deleted
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 6
lab-3-27@GCECSE-27:~$

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 :

i)SEQUENTIAL FILE ALLOCATION

AIM:

To implement sequential file allocation strategies

ALGORITHM:

1. Import the necessary preprocessor directives


2. Read the starting block and length of files
3. Print the whether the file is allocated or not.

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:

Thus the sequential allocation strategy is executed and verified successfully.


ii)INDEXED FILE ALLOCATION

AIM:

To implement indexed file allocation strategies

ALGORITHM:

1. Import the necessary preprocessor directives


2. Read the index block, blocks needed and number of files for the index
3. Print whether allocated or not

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:

lab-3-27@GCECSE-27:~$ gcc -o EX14index EX14index.C


lab-3-27@GCECSE-27:~$ ./EX14index
Enter the index block: 5
Enter no of blocks needed and no of files for the index 5 on the disk :
4
1234
Allocated
File Indexed
5 ------- >1 : 1
5-------->2 : 1
5-------->3 : 1
5-------->4 : 1
Do you want to enter more file(Yes - 1/No - 0)1
Enter the index block: 4
4 index is already allocated
Enter the index block: 6
Enter no of blocks needed and no of files for the index 6 on the disk :
2
78
Allocated
File Indexed
6 ------- >7 : 1
6-------->8 : 1
Do you want to enter more file(Yes - 1/No - 0)0
lab-3-27@GCECSE-27:~$

RESULT:

Thus the indexed allocation strategy is executed and verified successfully.


iii)LINKED FILE ALLOCATION

AIM:

To implement indexed file allocation strategies

ALGORITHM:

1. Import the necessary preprocessor directives


2. Read the index starting block and length
3. Print whether allocated or not

PROGRAM:

/* Program to simulate linked file allocation strategy */


#include<stdio.h>
#include<stdlib.h>
#include<stddef.h>
int 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++)
{s
canf("%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++)
{ 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);
}
OUTPUT:

lab-3-27@GCECSE-27:~$ gcc -o ex14linked ex14linked.c


lab-3-27@GCECSE-27:~$ ./ex14linked
Enter how many blocks already allocated: 3
Enter blocks already allocated: 1 3 5
Enter index starting block and length: 2 2
2 >1
3 Block is already allocated
4 >1
Do you want to enter more file(Yes - 1/No - 0)0
lab-3-27@GCECSE-27:~$

RESULT:

Thus the linked allocation strategy is executed and verified successfully.


Ex no : 15 IMPLEMENTATION OF DISK SCHEDULING ALGORITHMS

Date :

i)FCFS:

AIM:
To implement FCFS disk scheduling algorithm
ALGORITHM:

1. Import necessary preprocessor directives


2. Read number of seek operations
3. Print seek sequence

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:

To implement SSTF disk scheduling algorithm

ALGORITHM:

1. Import necessary preprocessor directives


2. Read number of request, request sequence, initial head position
3. Print total head movement

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:

lab-3-27@GCECSE-27:~$ gcc -o sstf sstf.c


lab-3-27@GCECSE-27:~$ ./sstf
Enter the number of Requests
8
Enter the Requests sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 236

RESULT:

Thus the SSTF disk scheduling algorithm is executed and verified successfully.
iii)SCAN(ELEVATOR)

AIM:

To implement SCAN disk scheduling algorithm

ALGORITHM:

1. Import necessary preprocessor directives


2. Read number of request, request sequence, initial head position
3. Print total head movement

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:

lab-3-27@GCECSE-27:~$ gcc -o scan scan.c


lab-3-27@GCECSE-27:~$ ./scan
Enter the number of Requests
8
Enter the Requests sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Enter total disk size
200
Enter the head movement direction for high 1 and for low 0
1
Total head movement is 337

RESULT:

Thus the SCAN disk scheduling algorithm is executed and verified successfully.
iv) C-SCAN

AIM:

To implement C-SCAN disk scheduling algorithm

ALGORITHM:

1. Import necessary preprocessor directives


2. Read number of request, request sequence, initial head position
3. Print total head movement

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:

To install guest operating system like linux using VM Ware

PROCEDURE:

Step 1: Download VM Ware Workstation from https://www.vmware.com

Step 2: Install it in the PC.

Step 3: Download the Ubuntu 18.04.6 version from website https://releases.ubuntu.com/18.04/


Step 4: Open the VM Ware Workstation and click New Virtual Machine

Step 5: Select Typical as type of configuration and click Next

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.

Step 10: Click Finish.


RESULT:
Thus the linux operating system is installed in VM Ware

You might also like