AL3452 Os Lab
AL3452 Os Lab
Index
Exp.no Name of the Experiment Page No. Date Signature
1 Installation of windows operating system
AIM:
Installation of Windows Operating Systems.
PROCEDURE:
In order to install our copy of the Windows7 operating system please make sure to have the
following items:
-Windows7 Installation disk
-Drivers CD: *Use after installation process if needed.
*NOTE:Please make sure to backup all of your important data before proceeding with this
installation.
Step1:Insert the Windows7 operating system disk into your DVD drive, and then restart your
computer
Step2:You will see aprompt that says ‘Press any key to continue’ after the ZT logo
disappears.When you see this press any key immediately.
*NOTE: The following screenshot may differ from what you may see during your
installation.(i.e.Win7version,HDD disk space etc..)
*NOTE:Deletingthepartitionswillerasealldataonthesystem
Step13:“SetupisstartingWindows”willappearonthescreen,thenyouwillbeaskedtocreatea
usernameandacomputername.
Step15:Thenextscreenwillcomeupandaskyoutochooseoneofthreeoptions:“Userecommend
edsettings”, “Installimportantupdatesonly”and“Askmelater”.
RESULT:
The Windows installation is done on the computer.
WHAT IS UNIX?
UNIX is an operating system which was first developed in the 1960s, and has been under
constant development ever since. By operating system, we mean the suite of programs
which make the computer work. It is a stable, multi-user, multi-tasking system for servers,
desktops and laptops.
UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows
which provides an easy to use environment. However, knowledge of UNIX is required for
operations which aren't covered by a graphical program, or for when there is no windows
interface available, for example, in a telnet session.
TYPES OF UNIX
There are many different versions of UNIX, although they share common similarities. The
most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.
Here in the School, we use Solaris on our servers and workstations, and Fedora Linux on the
servers and desktop PCs.
The UNIX operating system is made up of three parts; the kernel, the shell and the
programs.
THE KERNEL
The kernel of UNIX is the hub of the operating system: it allocates time and memory to
programs and handles the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user
types rm myfile (which has the effect of removing the filemyfile). The shell searches the
filestore for the file containing the program rm, and then requests the kernel, through
system calls, to execute the program rm on myfile. When the process rm myfile has
finished running, the shell then returns the UNIX prompt % to the user, indicating that it is
waiting for further commands.
THE SHELL
The shell acts as an interface between the user and the kernel. When a user logs in, the login
program checks the username and password, and then starts another program called the
shell. The shell is a command line interpreter (CLI). It interprets the commands the user
types in and arranges for them to be carried out. The commands are themselves programs:
when they terminate, the shell gives the user another prompt (% on our systems).
The adept user can customize his/her own shell, and users can use different shells on the
same machine. Staff and students in the school have the tcsh shell by default.
CS3461-OPERATING SYSTEMS LAB 10
The tcsh shell has certain features to help the user inputting commands.
Filename Completion - By typing part of the name of a command, filename or directory and
pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the
shell finds more than one name beginning with those letters you have typed, it will beep,
prompting you to type a few more letters before pressing the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to repeat a
command, use the cursor keys to scroll up and down the list or type history for a list of
previous commands.
A file is a collection of data. They are created by users using text editors, running compilers
etc.
Examples of files:
a directory, containing information about its contents, which may be a mixture of other
directories (subdirectories) and ordinary files.
The main concept that unites all versions of UNIX is the following four basics −
Kernel: The kernel is the heart of the operating system. It interacts with hardware and
most of the tasks like memory management, tash scheduling and file management.
Shell: The shell is the utility that processes your requests. When you type in a command
at your terminal, the shell interprets the command and calls the program that you want.
The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell
are most famous shells which are available with most of the Unix variants.
Commands and Utilities: There are various command and utilities which you would
use in your day to day activities. cp, mv, cat and grepetc. are few examples of
commands and utilities. There are over 250 standard commands plus numerous others
provided through 3rd party software. All the commands come along with various
optional options.
Files and Directories: All data in UNIX is organized into files. All files are organized
into directories. These directories are organized into a tree-like structure called the file
system.
All the files are grouped together in the directory structure. The file-system is arranged in a
hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally
called root (written as a slash / )
In the diagram above, we see that the home directory of the undergraduate
student "ee51vn" contains two sub-directories (docs and pics) and a file called report.doc.
When a program is started on UNIX, it creates what is known as a “process” on the system.
Every process is assigned a unique serial number called its process id or PID for short. Processes
can be created by any user, but can only be destroyed by someone with the permissions to do so
– usually the user that created the process or the system administrator. This ensures that the
compute jobs you start on the system will not be disturbed by any other user of the system until
they complete or you decide to stop them yourself.
Processes and process management becomes important on UNIX systems that are shared
between a number of users. The concept of users and PIDs is the main tool by which the
available system resources are shared fairly among everybody who needs access to them.
Processes can be suspended or given lower priority in cases where one or more users shoot step
out of the way for someone else, but wish to do so without losing their work of up to that point.
One further consideration on this topic is the fact that a running UNIX process can spawn
“child” processes. For example, any program you run from inside a UNIX Shell will be a child
process of that shell. Conversely, the shell is the parent process of this child. Child processes
have associated with them both their own process id (PID) as well as their parent’s process id
(PPID).
Normally this concept of parent and child processes is not something you need to be bothered
with as a user. However, it can be useful to understand how UNIX organizes processes if you are
trying to keep track of certain system resources (e.g. memory and CPU), if you are working with
environment variables, or if you need to track down a rogue program or script.
Date andTime
calendar
Echo
who am i
who
NAME
echo - display a line of text
SYNOPSIS
echo [OPTION]... [STRING]...
DESCRIPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version
output version information and exit
If -e is in effect, the following sequences are recognized:
\0NNN the character whose ASCII code is NNN (octal)
\\ backslash
\a alert (BEL)
\b backspace
\c suppress trailing newline
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
NOTE: your shell may have its own version of echo, which usually super-
sedes the version described here. Please refer to your shellΓÇÖs docu-
mentation for details about the options it supports.
AUTHOR
CS3461-OPERATING SYSTEMS LAB 15
Written by FIXME unknown.
:
bc
finger
id
[sce@localhost ~]$ id
uid=500(sce01) gid=501(sce) groups=501(sce)
uname
tr
ps
[sce@localhost ~]$ ps -e
PID TTY TIME CMD
1? 00:00:00 init
2? 00:00:00 migration/0
CS3461-OPERATING SYSTEMS LAB 16
3? 00:00:00 ksoftirqd/0
4? 00:00:00 watchdog/0
5? 00:00:00 migration/1
6? 00:00:00 ksoftirqd/1
7? 00:00:00 watchdog/1
8? 00:00:00 events/0
9? 00:00:00 events/1
10 ? 00:00:00 khelper
11 ? 00:00:00 kthread
15 ? 00:00:00 kblockd/0
16 ? 00:00:00 kblockd/1
2883 ? 00:00:00 login
2885 pts/1 00:00:00 bash
2937 pts/1 00:00:00 man
2969 pts/1 00:00:00 bc
2982 pts/1 00:00:00 tr
2984 pts/1 00:00:00 ps
[sce@localhost ~]$
tty
mkdir
[sce@localhost a]$ mkdir dir1
[sce01@localhost a]$ mkdir dir2
[scee01@localhost a]$ mkdir dir3
[scee01@localhost a]$ ls
dir1 dir2 dir3
rmdir
[sce@localhost a]$ rmdir dir3
[sce01@localhost a]$ ls
dir1 dir2
pwd
[sce@localhost a]$ pwd
/home/sce01/dir1/a
ls
[sce@localhost a]$ ls
dir1 dir2 file1
hi
welcome
to
scecollege
[sce@localhost a]$ ls
dir1 dir2 file1 file2
hi
welcome
to
scecollege
[sce@localhost a]$ mv file1 file2
[sce@localhost a]$ cat file1
CS3461-OPERATING SYSTEMS LAB 19
cat: file1: No such file or directory
To remove file1
[sce@localhost a]$
hi
welcome
to
scecollege
hi
welcome
to
scecollege
[sce@localhost a]$ ls
dir1 dir2 file1 file2
sort
cmp-to compare
Cut
RESULT:
The basic Unix commands are executed successfully.
AIM:
To write simple shell programs by using conditional statements.
ALGORITHM:
Step1:Start the program
Step2:Read the value of n
Step3:Calculate ‘r=expr $n%2’
Step 4:If the value of r equals 0 then print the number is even
Step5:If the value of r not equal to 0 then print the number is odd
Step 6:Stop the program
PROGRAM:
echo "enter the value of n:"
read n
r=`expr $n % 2`
if test $r -eq 0
then
echo "even number"
else
echo "odd number"
fi
OUTPUT:
RESULT:
AIM:
To write simple shell programs by using conditional statements.
ALGORITHM:
Step 1:Start the program
Step 2:Declare variables
Step 3:Start loop
Step 4:Get num1,operator,num2 value from user
Step 5:Start switch case and pass operator in switch case
Step 6:Write the case for arithmetic operators and their associated statements
Step 7:Define default in switch case
Step 8:Take input from the user to check loop continuity
Step 9:If the user enters yes then repeat steps 2-7
else end the loop.
Step 10:Stop the program
PROGRAM:
RESULT:
AIM:
To write simple shell programs by using WHILE loop.
ALGORITHM:
Step 1:Start the program
Step 2:Parse the command line arguments and store them in variables.
Stepn 3:Use a switch case statement to determine which command to execute based on the user input.
Step 4:For each case in the switch statement, execute the corresponding command using the appropriate syntax and
options.
Step 5:Use error handling to catch any errors that may occur during the execution of the command.
Step 6:Stop the program
PROGRAM:
RESULT: Thus simple shell programs by using while loop was executed.
AIM:
To write simple shell programs by using for loop.
ALGORITHM:
Step 1:Start the program
Step 2:Take an input from the user for the number of rows and columns they want in the multiplication table.
Step 3:Create a nested loop with outer loop iterating through the rows and inner loop iterating through the columns.
Step 4:Multiply the row number with the column number and store the result in a variable.
Step 5:Print the result to the console in a formatted way, such that the columns align with each other.
Step 6:Repeat step 3 and 4 until all rows and columns are filled.
Step 7:Stop the program.
PROGRAM:
OUTPUT:
RESULT:
Thus simple shell programs by using for loop was executed.
AIM:
To write simple shell programs for palindrome
ALGORITHM:
Step 1:Start the program
Step 2:Take an input from the user for the word or phrase to check.
Step 3:Convert the input to lowercase and remove all spaces and punctuation marks.
Step 4:Initialize two pointers, one at the beginning of the string and one at the end of the string.
Step 5:Compare the characters at the two pointers. If they are equal, move the pointers one position towards
each other.
Step 6:Repeat step 4 until the pointers meet in the middle of the string, or until a pair of characters are found
that are not equal.
Step 7:If the pointers met in the middle of the string, the input is a palindrome. If they did not meet in the
middle, the input is not a palindrome.
Step 8:Stop the program
PROGRAM:
RESULT:
AIM:
To write simple shell programs for Fibonacci series.
ALGORITHM:
Step 1:Start the program
Step 2:Take an input from the user for the number of terms to generate in the Fibonacci series.
Step 3:Initialize two variables, a and b, to the values 0 and 1 respectively.
Step 4:Print the value of a to the console.
Step 5:Repeat the following steps n-1 times, where n is the number of terms specified by the user:
a. Compute the next term in the Fibonacci series by adding a and b together.
b. Set a to the value of b.
c. Set b to the value of the next term computed in step 4a.
d. Print the value of a to the console.
Step 6:Stop the program.
PROGRAM:
echo "enter the limit"
read i
n=2
x=0
y=1
echo "fibonacci series"
echo $x
echo $y
while test $n -lt $i
do
z=`expr $x+$y|bc`
echo $z
x=$y
y=$z
n=`expr $n+1|bc`
done
RESULT:
Thus simple shell programs for Fibonacci series was completed successfully.
AIM:
To write simple shell programs for checking prime number .
ALGORITHM:
Step 1:Start the program
Step 2:Take an input from the user for the number to check.
Step 3:If the input is less than 2, print “Not a prime number” and exit the program.
Step 4:Initialize a variable is_prime to True.
Step 5:Loop through all numbers from 2 to the square root of the input number:
If the input number is divisible by the current number in the loop, set is_prime to False and exit the loop.
If is_prime is still True after the loop, print “Prime number” to the console.
Otherwise, print “Not a prime number” to the console.
Step 6:Stop the program.
PROGRAM:
RESULT:
Thus simple shell programs for checking prime number was completed successfully.
AIM:
To write C Programs using the following system calls of UNIX operating system fork,
exec, getpid, exit, wait, close.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Declare the variables pid,pid1,pid2.
STEP 3: Call fork() system call to create process.
STEP 4: If pid==-1, exit.
STEP 5: Ifpid!=-1 , get the process id using getpid().
STEP 6: Print the process id.
STEP 7:Stop the program
PROGRAM:
#include<stdio.h>
#include<unistd.h>
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);
}
RESULT:
Thus the C programs using the following system calls of UNIX operating system fork,
exec, getpid, exit, wait, close has been executed successfully.
AIM:
To write a C program to implement FCFS CPU Scheduling algorithms.
ALGORITHM:
Step 1: Inside the structure declare the variables.
Step 2: Declare the variable i,j as integer,totwtime and totttime is equal to zero.
Step 3: Get the value of „n‟ assign pid as I and get the value of p[i].btime.
Step 4: Assign p[0] wtime as zero and tot time as btime and inside the loop calculate wait time and
turnaround time.
Step 5: Calculate total wait time and total turnaround time by dividing by total number of process.
Step 6: Print total wait time and total turnaround time.
Step 7: Stop the program
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
struct fcfs
{
int pid,btime,wtime,ttime;
}
p[10];
int main()
{
int i,n;
int towtwtime=0,totttime=0;
printf("\n fcfs scheduling");
printf("enter the number of process");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i].pid=1;
printf("burst time of the process");
scanf("%d",&p[i].btime);
}
p[0].wtime=0;
p[0].ttime=p[0].btime;
totttime+=p[i].ttime;
for(i=0;i<n;i++)
{
p[i].wtime=p[i-1].wtime+p[i-1].btime;
p[i].ttime=p[i].wtime+p[i].btime;
totttime+=p[i].ttime;
towtwtime+=p[i].wtime;
}
for(i=0;i<n;i++)
{
printf("waiting tie of the process");
printf("turn around time for process");
printf("\n");
}
printf("\n total waiting time:%d",towtwtime);
printf("\n average waiting time:%f",(float)towtwtime);
printf("\n total turn around time:%d",totttime);
printf("\n average turn around time:%f",(float)totttime);
}
OUTPUT:
RESULT:
Thus the FCFS CPU scheduling algorithms has been executed successfully.
EX:NO:4B
CPU SCHEDULING ALGORITHMS- SJF SCHEDULING
DATE:
AIM:
To write a C program to implement SJF CPU Scheduling algorithms.
ALGORITHM:
Step 1: Inside the structure declare the variables.
Step 2: Declare the variable i,j as integer,totwtime and totttime is equal to zero.
Step 3: Get the value of „n‟ assign pid as I and get the value of p[i].btime
Step 4: Assign p[0] wtime as zero and tot time as btime and inside the loop calculate wait time
and turnaround time.
Step 5: Calculate total wait time and total turnaround time by dividing by total number of
process.
Step 6: Print total wait time and total turnaround time.
Step 7: Stop the program.
PROGRAM:
#include<stdio.h>
int main()
{
int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10],i;
float att=0,awt=0;
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
printf("enter the number of process");
scanf("%d",&n);
printf("enter the burst times");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
p[i]=i;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
temp1=p[i];
RESULT:
Thus the SJF CPU scheduling algorithms has been executed successfully.
AIM:
To write a C program to implement Priority Scheduling algorithms.
ALGORITHM:
Step 1: Inside the structure declare the variables.
Step 2: Declare the variable i,j as integer, totwtime and totttime is equal to zero.
Step 3: Get the value of „n‟ assign p and allocate the memory.
Step 4: Inside the for loop get the value of burst time and priority.
Step 5: Assign wtime as zero .
Step 6: Check p[i].pri is greater than p[j].pri .
Step 7: Calculate the total of burst time and waiting time and assign as turnaround time.
Step 8: Stop the program.
PROGRAM:
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
printf("\nEnter Burst Time and Priority\n");
for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1;
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n;
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n;
printf("\n\nAverage Waiting Time=%d",avg_wt);
printf("\nAverage Turnaround Time=%d\n",avg_tat);
return 0;
}
RESULT:
Thus the priority CPU scheduling algorithms has been executed successfully.
AIM:
To write a C program to implement Round Robin algorithms.
ALGORITHM:
Step 1: Declare and initialize variables: count, j, n, time, remain, flag, time_quantum, wait_time,
turnaround_time.
Step 2: Declare arrays to store arrival time (at), burst time (bt), and remaining time (rt) for each
process.
Step 3: Read the time quantum (time_quantum).
Step 4: Start a loop until all processes are executed (remain is not 0).
Step 5: Check if the remaining time of the current process (rt[count]) is less than or equal to the
time quantum (time_quantum) and greater than 0
Step 7: Calculate the total of burst time and waiting time and assign as turnaround time.
Step 8: Stop the execution of program.
PROGRAM:
#include<stdio.h>
int main()
{
int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
RESULT:
Thus the round robin CPU scheduling algorithms has been executed successfully.
AIM:
To write a c program to implement IPC using shared memory.
ALGORITHM:
Step 1: Start the process
Step 2: Declare the segment size
Step 3: Create the shared memory
Step 4: Read the data from the shared memory
Step 5: Write the data to the shared memory
Step 6: Edit the data
Step 7: Stop the process
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
{
printf("creating a new shared memory seg \n");
RESULT:
Thus the c program for IPC has been executed successfully.
AIM:
To write a C-program to implement the producer – consumer problem for mutual exclusion using
semaphores.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the required variables.
Step 3: Initialize the buffer size and get maximum item you want to produce.
Step 4: Get the option, which you want to do either producer, consumer or exit from the
operation.
Step 5: If you select the producer, check the buffer size if it is full the producer should not
produce the item or otherwise produce the item and increase the value buffer size.
Step 6: If you select the consumer, check the buffer size if it is empty the consumer should not
consume the item or otherwise consume the item and decrease the value of buffer size.
Step 7: If you select exit come out of the program. Step 8: Stop the program.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int mutex=1,full=0,empty=3,x=0;
int main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n1.Producer\n2.Consumer\n3.Exit");
while(1)
{
printf("\nEnter your choice:");
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();
RESULT:
Thus the implementation of mutual exclusion by Semaphore using C program has been
executed successfully.
AIM:
To write a C program to implement banker‟s algorithm for deadlock avoidance.
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the memory for the process.
Step-3: Read the number of process, resources, allocation matrix and available matrix.
Step-4: Compare each and every process using the banker‟s algorithm.
Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a deadlock
process
Step-6: produce the result of state of process
Step-7: Stop the program
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int Max[10][10], need[10][10], alloc[10][10], avail[10], completed[10], safeSequence[10];
int p, r, i, j, process, count;
count = 0;
printf("Enter the no of processes : ");
scanf("%d", &p);
for(i = 0; i< p; i++)
completed[i] = 0;
printf("\n\nEnter the no of resources : ");
scanf("%d", &r);
printf("\n\nEnter the Max Matrix for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ", i + 1);
for(j = 0; j < r; j++)
scanf("%d", &Max[i][j]);
}
printf("\n\nEnter the allocation for each process : ");
for(i = 0; i < p; i++)
{
printf("\nFor process %d : ",i + 1);
for(j = 0; j < r; j++)
scanf("%d", &alloc[i][j]);
AIM:
To write a C program to implement algorithm for deadlock detection.
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the memory for the process.
Step-3: Read the number of process, resources, allocation matrix and available matrix.
Step-4: Compare each and every process using the banker‟s algorithm.
Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a deadlock
process .produce the result of state of process
Step-6 : Stop the program
PROGRAM:
#include<stdio.h>
int max[100][100],alloc[100][100],need[100][100],avail[100],n,r;
void input();
void show();
void cal();
int main()
{
int i,j;
printf("\n dead lock detection algm");
input();
show();
cal();
}
void input()
{
int i,j;
printf("\n eneter the no. of process");
scanf("%d",&n);
printf("\n enter the no. of instants");
scanf("%d",&r);
printf("\n enter the max matrix");
for(i=0;i<n;i++)
for(j=0;j<r;j++)
scanf("%d",&max[i][j]);
printf("enter the allocation matrix:");
for(i=0;i<n;i++)
RESULT:
Thus the Deadlock Detection Algorithm has been executed successfully.
AIM:
To write a c program to implement Threading and Synchronization Applications.
ALGORITHM:
Step 1: Start the process
Step 2: Declare process thread, thread-id.
Step 3: Read the process thread and thread state.
Step 4: Check the process thread equals to thread-id by using if condition.
Step 5: Check the error state of the thread.
Step 6: Display the completed thread process. Step 7: Stop the process
Step 7:Stop the Process
PROGRAM
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int MAX = 10;
int count = 1;
pthread_mutex_t thr;
pthread_cond_t cond;
void *even(void *arg){
while(count < MAX) {
pthread_mutex_lock(&thr);
while(count % 2 != 0) {
pthread_cond_wait(&cond, &thr);
}
printf("%d ", count++);
pthread_mutex_unlock(&thr);
pthread_cond_signal(&cond);
}
pthread_exit(0);
}
void *odd(void *arg){
while(count < MAX) {
pthread_mutex_lock(&thr);
while(count % 2 != 1) {
pthread_cond_wait(&cond, &thr);
}
printf("%d ", count++);
pthread_mutex_unlock(&thr);
pthread_cond_signal(&cond);
OUTPUT:
RESULT:
Thus the C program for threading has been executed successfully.
AIM:
To write a C program for Paging Techniques.
ALGORITHM:
Step 1: Start the process
Step 2: Declare page number, page table, frame number and process size.
Step 3: Read the process size, total number of pages
Step 4: Read the relative address
Step 5: Calculate the physical address
Step 6: Display the address
Step 7: Stop the process
PROGRAM:
#include<stdio.h>
int main()
{
int lmem[10][10],pmem[10][10],ptabel[10],psize,i,j,n,phyadd;
printf("\nPAGING");
printf("\nenter the number of pages");
scanf("%d",&n);
printf("\nenter the page size");
scanf("%d",&psize);
printf("\nenter the data values to be stored");
for(i=0;i<n;i++)
{
for(j=0;j<psize;j++)
{
printf("\nenter the values for %d%d=",i,j);
scanf("%d",&lmem[i][j]);
}
}
for(i=0;i<n;i++)
{
printf("\nenter the basic addr for %d page:",i);
scanf("%d",&ptabel[i]);
}
printf("\n*****LOGICAL MEMORY*****");
printf("\npage number\toffset\tvalue");
for(i=0;i<n;i++)
RESULT:
Thus the C program for Paging has been executed successfully.
AIM:
To write a C program for implementation memory allocation methods for fixed partition using
first fit.
ALGORITHM:
Step 1:Define the max as 25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0, bf[max],ff[max].
Step 3: Get the number of blocks,files,size of the blocks using for loop.
Step 4: In for loop check bf[j]!=1, if so temp=b[j]-f[i]
Step 5: Check highest<temp,if so assign ff[i]=j,highest=temp
Step 6: Assign frag[i]=highest, bf[ff[i]]=1,highest=0
Step 7: Repeat step 4 to step 6.
Step 8: Print file no,size,block no,size and fragment.
Step 9: Stop the program.
PROGRAM:
#include<stdio.h>
#define max 25
int main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
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++)
RESULT:
Thus the C program for first fit memory allocation has been executed successfully.
AIM:
To write a C program for implementation memory allocation methods for fixed partition using
best fit..
ALGORITHM:
Step 1:Define the max as 25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0, bf[max],ff[max].
Step 3: Get the number of blocks,files,size of the blocks using for loop.
Step 4: In for loop check bf[j]!=1, if so temp=b[j]-f[i]
Step 5: Check lowest>temp,if so assign ff[i]=j,highest=temp
Step 6: Assign frag[i]=lowest, bf[ff[i]]=1,lowest=10000
Step 7: Repeat step 4 to step 6.
Step 8: Print file no,size,block no,size and fragment.
Step 9: Stop the program.
PROGRAM:
#include<stdio.h>
#define max 25
int main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
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++)
{
OUTPUT:
RESULT:
Thus the C program for best fit memory allocation has been executed successfully.
AIM:
To write a C program for implementation memory allocation methods for fixed partition using
worst fit..
ALGORITHM:
Step 1:Define the max as 25.
Step 2: Declare the variable frag[max],b[max],f[max],i,j,nb,nf,temp, highest=0, bf[max],ff[max].
Step 3: Get the number of blocks,files,size of the blocks using for loop.
Step 4: In for loop check bf[j]!=1, if so temp=b[j]-f[i]
Step 5: Check temp>=0,if so assign ff[i]=j break the for loop.
Step 6: Assign frag[i]=temp,bf[ff[i]]=1;
Step 7: Repeat step 4 to step 6.
Step 8: Print file no,size,block no,size and fragment.
Step 9: Stop the program.
PROGRAM:
#include<stdio.h>
#define max 25
int main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
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]);
}
OUTPUT:
RESULT:
Thus the C program for worst fit memory allocation has been executed successfully.
AIM:
To write a C program for implementation of FIFO page replacement algorithm.
ALGORITHM:
Step 1: Start the program.
Step 2: Declare the necessary variables.
Step 3: Enter the number of frames.
Step 4: Enter the reference string end with zero.
Step 5: FIFO page replacement selects the page that has been in memory the longest time and
when the page must be replaced the oldest page is chosen.
Step 6: When a page is brought into memory, it is inserted at the tail of the queue.
Step 7: Initially all the three frames are empty.
Step 8: The page fault range increases as the no of allocated frames also increases.
Step 9: Print the total number of page faults.
Step 10: Stop the program.
PROGRAM:
#include<stdio.h>
int fr[3];
void display()
{
int i;
printf("\n");
for (i = 0; i < 3; i++)
printf("%d\t", fr[i]);
}
void main() {
int i, j;
int page[12] = {2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2};
int flag1 = 0, flag2 = 0, pf = 0, frsize = 3, top = 0;
for (i = 0; i < 3; i++)
{
fr[i] = -1;
}
for (j = 0; j < 12; j++)
{
flag1 = 0;
flag2 = 0;
for (i = 0; i < frsize; i++)
{
OUTPUT:
RESULT:
Thus the various FIFO Page Replacement Algorithms has been executed successfully.
AIM:
To write a c program to implement LRU page replacement algorithm.
ALGORITHM:
Step 1: Start the process
Step 2: Declare the size
Step 3: Get the number of pages to be inserted
Step 4: Get the value
Step 5: Declare counter and stack
Step 6: Select the least recently used page by counter value
Step 7: Stack them according the selection.
Step 8: Display the values
Step 9: Stop the process
PROGRAM:
#include<stdio.h>
#include<conio.h>
int fr[3];
void main()
{
void display();
int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
int index,k,l,flag1=0,flag2=0,pf=0,frsize=3;
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;
flag2=1;
break;
}
}
RESULT:
Thus the various LRU Page Replacement Algorithms has been executed successfully.
AIM:
To write C program to organize the file using single level directory
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the count, file name, graphical interface.
Step-3: Read the number of files
Step-4: Read the file name
Step-5: Declare the root directory
Step-6: Using the file eclipse function define the files in a single level
Step-7: Display the files
Step-8: Stop the program
PROGRAM:
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch;
char f[30];
dir.fcnt = 0;
printf("\nEnter name of directory -- ");
scanf("%s", dir.dname);
while(1)
{
printf("\n\n1. 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("\nEnter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
RESULT:
Thus the program to organize the file using single level directory has been executed successfully
AIM:
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the count, file name, graphical interface.
Step-3: Read the number of files
Step-4: Read the file name
Step-5: Declare the root directory
Step-6: Using the file eclipse function define the files in a single level
Step-7: Display the files
Step-8: Stop the program
PROGRAM:
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
{
int i,ch,dcnt,k;
char f[30], d[30];
dcnt=0;
while(1)
{
printf("\n\n1. Create Directory\t2. Create File\t3. Delete File");
printf("\n4. Search File\t\t5. Display\t6. Exit\tEnter your choice -- ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter name of directory -- ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
}
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++)
RESULT:
Thus the program to organize the file using two level directory has been executed successfully.
AIM:
To write a C program for sequential file allocation
ALGORITHM:
Step-1: Start the program.
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-4: Store the entered information in the system.
Step-5: Using do..While statement and switch case to create the options such as
1-DISPLAY, 2.SEARCH, 3.EXIT.
Step-6: Close the file using fclose() function.
Step-7: Process it and display the result.
Step-8: Stop the program.
PROGRAM:
#include<stdio.h>
struct file
{
char fname[10];
int start;
int size,block[10];
}f[10];
main()
{
int i,j,n;
printf("\n enter the number of files");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the file name:");
scanf("%s",f[i].fname);
printf("\n enter the starting block");
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("\n enter the number of size");
scanf("%d",&f[i].size);
}
printf("\n file\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
OUTPUT:
RESULT:
Thus the various Sequential File Allocation methods has been executed successfully.
AIM:
To write a C program for linked file allocation
ALGORITHM:
Step-1: Start the program.
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-4: Store the entered information in the system.
Step-5: Using do..While statement and switch case to create the options such as
1-DISPLAY, 2.SEARCH, 3.EXIT.
Step-6: Close the file using fclose() function.
Step-7: Process it and display the result.
Step-8: Stop the program.
PROGRAM
#include <stdio.h>
struct file {
char fname[10];
int start;
int size;
int block[10];
} f[10];
void display(int n);
int main() {
int i, j, n;
printf("Enter the number of files: ");
scanf("%d", &n);
OUTPUT:
RESULT:
Thus the various Linked File Allocation methods has been executed successfully.
AIM:
To write a C program for index file allocation
ALGORITHM:
Step-1: Start the program.
Step-2: Get the number of records user want to store in the system.
Step-3: Using Standard Library function open the file to write the data into the file.
Step-4: Store the entered information in the system.
Step-5: Using do..While statement and switch case to create the options such as
1-DISPLAY, 2.SEARCH, 3.EXIT.
Step-6: Close the file using fclose() function.
Step-7: Process it and display the result.
Step-8: Stop the program.
PROGRAM:
#include <stdio.h>
int main()
{
int f[50], i, j, indexBlock, n, c;
int index[50];
for (i = 0; i < 50; i++)
{
f[i] = 0;
}
while (1)
{
printf("\nEnter the index block: ");
scanf("%d", &indexBlock);
if (f[indexBlock] == 0)
{
f[indexBlock] = 1;
printf("Enter the number of blocks for the file: ");
scanf("%d", &n);
} else {
printf("Block already allocated, try another block.\n");
continue;
}
printf("Enter the block numbers:\n");
for (i = 0; i < n; i++) {
scanf("%d", &index[i]);
RESULT:
Thus the various Indexed File Allocation methods has been executed successfully.
AIM:
To write a C program for implementing disk scheduling algorithm
ALGORITHM:
Step 1:Start the program
Step 2:Let Request array represents an array storing indexes of tracks that have been requested in
ascending order of their time of arrival. ‘head’ is the position of disk head.
Step 3:Let us one by one take the tracks in default order and calculate the absolute distance of the
track from the head.
Step 4:Increment the total seek count with this distance.
Step 5:Currently serviced track position now becomes the new head position.
Step 6:Go to step 2 until all tracks in request array have not been serviced.
Step 7:Stop the program
PROGRAM:
#include <stdio.h>
#include <stdlib.h> // For abs()
int main() {
int queue[20], n, head, i, j, seek = 0, max, diff;
float avg;
return 0;
}
OUTPUT:
RESULT:
Thus the program for the implementation of FCFS disk scheduling algorithms has been
executed successfully.
AIM:
To write a C program for implementing SSTF disk scheduling algorithm
ALGORITHM:
Step 1:Start the program
Step 2:Let Request array represents an array storing indexes of tracks that have been requested.
‘head’ is the position of disk head.
Step 3:Find the positive distance of all tracks in the request array from head.
Step 4:Find a track from requested array which has not been accessed/serviced yet and has
minimum distance from head.
Step 5:Increment the total seek count with this distance.
Step 6:Currently serviced track position now becomes the new head position.
Step 7:Go to step 2 until all tracks in request array have not been serviced.
Step 8:Stop the program
PROGRAM:
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,n,k,req[50],mov=0,cp,index[50],min,a[50],j=0,mini,cp1;
printf("enter the current position\n");
scanf("%d",&cp);
printf("enter the number of requests\n");
scanf("%d",&n);
cp1=cp;
printf("enter the request order\n");
for(i=0;i<n;i++)
{
scanf("%d",&req[i]);
}
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
{
index[i]=abs(cp-req[i]);
}
min=index[0];
mini=0;
for(i=1;i<n;i++)
OUTPUT:
RESULT:
Thus the program for the implementation of SSTF disk scheduling algorithms has been executed
successfully.