AL3452 - OS Lab Record
AL3452 - OS Lab Record
ACADEMIC YEAR
2023-2024
EVEN SEMESTER
SEMESTER :
Department of AI&DS AGNI COLLEGE OF TECHNOLOGY
BONAFIDE CERTIFICATE
Register Number :
PROCEDURE:
Let's start to install a clean and fresh Windows 10. Follow the steps given below:
https://www.microsoft.com/en-us/software-download/windows10startfresh
o You can see that the tool is downloaded now. Now, run the downloaded file.
o Accept the license term. Now, you will be asked to "Give your PC a fresh start."
o Choose any one of the options given below. Select what you want to keep.
o Now, select "Create installation media for another PC" option. See the below image:
o Now, you can copy the Windows 10 installation files to a USB drive or burn them to a DVD. The
Windows 10 installation files occupy the space greater than 3 GB so, your USB drive must be 4 GB or
larger in size. The USB drive must be empty because all files in the USB drive will be
erased in this process.
o Now, the installation media is created. Please insert it into your laptop or PC and
install Windows 10. You have to boot to the Windows 10 installer. For the booting
process, Click on the Start menu button and restart your laptop.
o Now, press and hold Del or F2 button to enter setup. This key may be different in some
computers. Generally, it is displayed as a message on startup that says, "Press [key] to enter setup."
o Now, go to the "Boot" option on the above menu bar and select a device from
which you have to boot. You will see the following two option there:
1. For a USB flash drive, select the Removable Devices option.
2. For a disc installation, select the CD-ROM Drive option.
o Now, save your setting and press the Enter button to confirm the changes. Now,
wait for your PC to restart.
o Now, the installation is started. Select your language, time, and currency format
on the Windows setup screen and then click "Next" to continue.
o You may have to click on several "next" buttons, and finally, you will see the
installer screen. See the below image:
o Click on the install now button and follow the given instructions to install
Windows 10 on your system successfully.
o Windows 10 is installed successfully. Now, you will see the Activate Windows
screen. You can enter a key or skip it. If installing Windows 10 automatically detects a
key associated with your PC's hardware, you will not see it on your screen.
o If you have a valid product key for Windows 10, you can paste it here. You can
also paste a valid Windows 7, 8, or 8.1 key here. You will get the advantage of the free
Windows 10 upgrade offer on your PC.
o After that, you will see a new Windows setup screen "Which type of installation do you
want?" Click "Custom" if you want to perform a clean installation. It will remove everything on
your PC. If you want to upgrade your existing installation, click the "Upgrade" option.
o Select the hard drive partition where you want to install Windows. It will delete the data you
have in that partition. Make sure that you have backups of any important files before doing this.
o In this installation process, your system may restart several times. At the end of
the process, you will get a new Windows 10 as your operating system.
RESULT:
These are the procedure to be followed to install Windows Operating System in our computer.
EX NO: 2 Illustrate UNIX commands and Shell Programming
AIM:
PROCEDURE:
GENERAL COMMANDS:
Command Function
Command Function
pwd Path of the present working directory
mkdirdir A directory is created in the given name under the current directory.
mkdirdir1 dir2 A number of sub-directories can be created under one stroke
Change Directory. If the subdirstarts with / then path starts from root
cd subdir
(absolute) otherwise from current working directory.
Cd To switch to the home directory.
cd / To switch to the root directory.
cd.. To move back to the parent directory
rmdirsubdir Removes an empty sub-directory.
FILE COMMANDS:
Command Function
To create a file with some contents. To end typing press Ctrl+d. The >symbol
cat >filename
means redirecting output to a file. (<for input)
cpsrc des Copy files to given location. If already exists, it will be overwritten
cp –isrc des Warns the user prior to overwriting the destination file
cp –r src des Copies the entire directory, all its sub-directories and files.
mv old new To rename an existing file or directory. –i option can also be used
Rmfile Used to delete a file or group of files. –i option can also be used
cmpfile1 file2 Used to compare two files. Displays nothing if files are identical.
1. To create a file.
Syntax: $ cat>filename
Example: $ cat>ex1
8. To delete a file
Syntax: $ rm filename
Example: $ rm ex1
Syntax: $ rm *
Syntax: $ mkdirdirname
13. Echo
Syntax: $ bc
Syntax: $ uname –n
v. To display the version number of the OS
Syntax: $ uname –r
15. Head
Syntax: $ wc filename
Example: $ wc ex1
Syntax: $ nl filename
Example: $ nl ex1
19. Sort
i. To reverse and sort the content of file
Syntax: $ ./filename
1. Calendar:
i. To display the calendar.
Syntax: $ cal
2. Date:
Syntax: $ date+%m
Syntax: $ date+%h
Output: Jan
Syntax: $ date+%r
Output: 10: 53:24 AM
viii. To display date of
month Syntax: $
date+%d Output: 20
3. WHO
i. To display the login details
Syntax: $ who
Output: root :0 Jan 20 10:51
cs1010 pts/0 Jan 20 10:51 (172.16.1.72)
Syntax: $ logname
Output: cs1010
4. MAN
i. It is used to view more details of all the
AIM:
To write simple shell scripts using shell programming fundamentals.
PROCEDURE:
The original UNIX came with the Bourne shell (sh) and it is universal even today.
Then came a plethora of shells offering new features. Two of them, C shell (csh)
and Korn shell (ksh) has been well accepted by the UNIX fraternity. Linux offers
Bash shell (bash) as a superior alternative to Bourne shell.
Preliminaries
1. Comments in shell script start with #. It can be placed anywhere in a line; the shell
ignores contents to its right. Comments are recommended but not mandatory
2. Shell variables are loosely typed i.e. not declared. Their type depends on the value
assigned. Variables when used in an expression or output must be prefixed by $.
3. The read statement is shell's internal tool for making scripts interactive.
4. Output is displayed using echo statement. Any text should be within quotes.
Escape sequence should be used with –e option.
6. Expressions are computed using the expr command. Arithmetic operators are
+ - * / %. Meta characters * ( ) should be escaped with a \.
8. The shell scripts are executed using the sh command (sh filename).
I. Swapping values of two variables
Algorithm
Step 1 : Start
t=aa=bb=t
Step 5 : Stop
b=$t
[student@vecit~]$sh swap.sh
Algorithm
Step 1: Start
Step 5: Stop
Program
# Degree conversion
read f
c=`expr\( $f - 32 \) \* 5 / 9`
Output
[student@vecit~]$sh temp.sh
Enter Fahrenheit:4
Algorithm
Step 1 : Start
Step 2 : Read number
Step 3 : If number divisible by 2 then Print "Number is Even"
else
Output
[student@vecit~]$sh oddeven.sh
Enter a non-zero number : 12
12 is Even
IV. String comparison
Algorithm
Step 1 : Start
Step 2 : Read strings str1 and str2
Step 3 : If str1 = str2 then Print "Strings are the same"
Program
Output
[student@vecit~]$sh strcomp.sh
Enter the first string :ece-a
Enter the second string : ECE-A
Strings are distinct
ALGORITHM:
1. Start the program.
2. Read the input from the command line.
3. Use fork() system call to create process, getppid() system call used to get the
parent process ID and getpid() system call used to get the current process ID
4. execvp() system call used to execute that command given on that command line argument
PROGRAM:
#include<stdio.h>
main(int arc,char*ar[])
{
int pid; char s[100]; pid=fork();
if(pid<0)
printf("error");
else if(pid>0)
{
wait(NULL);
printf("\n Parent Process:\n"); printf("\n\tParent Process
id:%d\t\n",getpid()); execlp("cat","cat",ar[1],(char*)0);
error("can’t execute cat %s,",ar[1]);
}
else
{
printf("\nChild process:");
printf("\n\tChildprocess parent id:\t %d",getppid());
write(1,s,strlen(s));
printf(" ");
printf(" ");
printf(" ");
execvp(ar[2],&ar[2]);
error("can’t execute %s",ar[2]);
}
}
OUTPUT:
[root@localhost~]# ./a.outtst date Child process:
Child process id :
3137 Sat Apr 10 02:45:32 IST 2010
Parent Process:
Parent Process id:3136 sd
dsaASD[root@localhost ~]# cat tstsd
dsaASD
3B) To write a program to implement the system callopendir, readdir, closedir
AIM: To write the program to implement the system calls opendir( ), readdir ( ),closedir ().
ALGORITHM:
}
while((direntp=readdir(dirp))!=NULL)
printf("%s\n",direntp->d_name);
while((closedir(dirp)==-1)&&(errno==EINTR));
return 0;
}
OUTPUT:
$ vi direc.c
$ cc direc.c
$ ./a.out ./
f1.txt
fflag.c b2
comm.c
dir1
demo2 a1
m1 db
a.out
direc.c
db1
file1
b1
xyz
abc
aaa
file2
aaa.txt
m2
DESCRIPTION:
P0 -0=0
P1 -1=4
P2 -2=6
P3 -3=13
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its turnaround time
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg =wtavg + wt[i];
tatavg = tatavg + tat[i];
}
printf("\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND
TIME\n"); for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i],
tat[i]); printf("\nAverage Waiting Time -- %f", wtavg/n);
INPUT
Enter the number of processes -- 3
Enter Burst Time for Process 0 -- 24
Enter Burst Time for Process 1 -- 3
Enter Burst Time for Process 2 -- 3
OUTPUT
PROCESS BURST TIME WAITING TIME TURNAROUND
TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time--17.000000
Average Turnaround Time -- 27.000000
4 B) SJF CPU SCHEDULING ALGORITHM
AIM:
DESCRIPTION:
Easy to implement in Batch systems where required CPU time is known in advance.
Impossible to implement in interactive systems where required CPU time is not known.
The processer should know in advance how much time process will take.
P0 5
P1 3
P2 8
P3 6
Waiting time of each process is as follows –
P0 0-0=0
P1 5-1=4
P2 14-2=12
P3 8-3=5
ALGORITHM:
Step 1: Start the process
Step 3: For each process in the ready Q, assign the process id and
accept the CPU burst time
Step 5: Set the waiting time of the first process as ‗0‘ and its
turnaround time as its burst time.
queue, calculate
Step 8: Calculate
c) Average waiting time = Total waiting Time / Number of process
d) Average Turnaround time = Total Turnaround Time / Number of process
PROGRAM :
#include<stdio.h>
#include<conio.h>
main()
{
p[i]=i;
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0]; for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i];
tatavg = tatavg + tat[i];
}
for(i=0;i<n;i++)
DESCRIPTION
P0 (0-0) + (12 - 3) = 9
P1 (3-1) = 2
Step 2: Accept the number of processes in the ready Queue and time
quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and
accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where
No. of time slice for process (n) = burst time process (n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 7: Calculate
#include<stdio.h>
main()
{
inti,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
clrscr();
printf("Enter the no of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]- ct[i];
att+=tat[i];
awt+=wa[i];
}
printf("\nThe Average Turnaround time is -- f",att/n);
TIME\n"); for(i=0;i<n;i++)
getch();
}
INPUT:
OUTPUT:
PROCESS BURST TIME WAITING TIME TURNAROUNDTIME
1 24 6 30
2 3 4 7
3 3 7 10
The Average Turnaround time is – 15.666667 The
Average Waiting time is ------------ 5.666667
4 D) PRIORITY CPU SCHEDULING ALGORITHM
AIM:
To write a C program to implement Priority CPU scheduling algorithm.
ALGORITHM:
Step 4: Compute the waiting time and turnaround time for each process.
Step 5: Calculate the average waiting time and average turnaround time.
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
float sum1=0,sum=0,awt,att;
char p[5][9],y[9];
printf("\nenter the number of process");
scanf("%d",&np);
printf("\nEnter the process,burst-time and
priority:"); for(i=0;i<np;i++)
scanf("%s%d%d",p[i],&bt[i],&pr[i]);
printf("\nEnter the arrival-time:");
for(i=0;i<np;i++)scanf("%d",&at[i]);
for(i=0;i<np;i++)
for(j=i+1;j<np;j++)
if(pr[i]>pr[j])
{
x=pr[j];
pr[j]=pr[i];
pr[i]=x;
strcpy(y,p[j]);
strcpy(p[j],p[i]);
strcpy(p[i],y);
z=bt[j];
bt[j]=bt[i];
bt[i]=z;
}
}
wt[0]=0;
for(i=1;i<=np;i++)
wt[i]=wt[i-1]+bt[i-1];
ft[0]=bt[0];
for(i=1;i<np;i++)
ft[i]=ft[i-1]+bt[i];
printf("\n\n\t\tGANTT CHART\n");
printf("\n \n");
for(i=0;i<np;i++)
printf("|\t%s\t",p[i]);
printf("|\t\n");
printf("\n \n");
printf("\n");
for(i=0;i<=np;i++)
printf("%d\t\t",wt[i]);
printf("\n \n");
printf("\n");
for(i=0;i<np;i++)
wat[i]=wt[i]-at[i];
for(i=0;i<np;i++)
tat[i]=wat[i]-at[i];
printf("\nPRIORITY SCHEDULING:\n");
printf("\nProcess Priority Burst-time Arrival-time Waiting-time Turnaround-time");
for(i=0;i<np;i++)
printf("\n\n%d%s\t%d\t\t%d\t\t%d\t%d\t\t%d",i+1,p[i],pr[i],bt[i],at[i],wt[i],tat[i]);
for(i=0;i<np;i++)
sum=sum+wat[i];
awt=sum/np;
for(i=0;i<np;i++)
sum1=sum1+tat[i];
att=sum1/np;
printf("\n\nAverage waiting time:%f",awt); printf("\n\nAverageturn around time is:%f",att);
}
OUTPUT:
p2 4 2
p3 5 1
Enter the arrival-time: 0 1 2
GANTT CHART
| p3 | p2 | p1 |
0 5 9 12
PRIORITY SCHEDULING:
p3 1 5 0 0 0
p2 2 4 1 5 3
p1 3 3 2 9 5
Average waiting time: 3.666667
RESULT
The CPU scheduling algorithms are implemented and executed successfully.
EX NO 5: INTERPROCESS COMMUNICATION
AIM:
DESCRIPTION:
one process with another process. This usually occurs only in one system.
Between related processes initiating from only one process, such as parent and child processes.
Following are some important terms that we need to know before proceeding further on this
topic. Pipes − Communication between two related processes. The mechanism is half duplex
meaning the first process communicates with the second process. To achieve a full duplex i.e.,
for the second process to communicate with the first process another pipe is required.
FIFO − Communication between two unrelated processes. FIFO is a full duplex, meaning the
first process can communicate with the second process and vice versa at the same time.
Message Queues − Communication between two or more processes with full duplex capacity. The
processes will communicate with each other by posting a message and retrieving it out of the
int ser[2],cli[2],pid;
char inbuff[msgsize];
char *msg="Thank you";
system("clear");
pipe(ser);
pipe(cli);
{
printf("\n i am in child process !");
close(cli[0]);
close(ser[1]);
write(cli[1],msg,msgsize);
sleep(2);
read(ser[0],inbuff,msgsize);
printf("\n echo message received from server");
printf("\n %s",inbuff);
}
else
{
close(cli[1]);
close(ser[0]);
printf("\n parent process");
read(cli[0],inbuff,msgsize);
write(ser[1],inbuff,msgsize);
printf("\n parent ended!");
}
}
OUTPUT:
$ vi echopipe.c
$ cc echopipe.c
$ ./a.out
server read id =3,write
parent ended!
$ message written to pipe..! echo
{
perror("\n message sending failed");
exit(1);
}
printf("\n message has been posted");
sleep(2);
if(msgrcv(qid,&recv,100,2,0)==-1)
{
send.mtype=2;
strcpy(send.mtext,"\n hi i am child");
len=strlen(send.mtext);
if(msgrcv(qid,&recv,100,1,0)==-1)
{
perror("\n child message received failed");
exit(1);
}
if(msgsnd(qid,&send,len,0)==-1)
{
perror("\n child message send failed");
}
}
}
OUTPUT:
$ vi echomsg.c
$ cc echomsg.c
$ ./a.out
hi i am child
RESULT:
AIM:
To write a C program to implement the Producer & consumer Problem (Semaphore)
ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.
ii) If there is empty space in the buffer check the mutex value for enter into the critical section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable to the
buffer.
If there is any item in the buffer check for mutex value, if the mutex==0,
remove item from buffer
#include<stdio.>
void main()
{
int buffer[10], bufsize, in, out, produce, consume,choice=0; in = 0;out = 0;
bufsize = 10;
while(choice !=3)
{
printf(“\n1. Produce \t 2. Consume \t3. Exit”); printf(“\nEnter your choice: ”);
scanf(“%d”,&choice);
switch(choice) {
case 1: if((in+1)%bufsize==out)
printf(“\nBuffer is Full”);
else
{
printf(“\nEnter the value: “);
scanf(“%d”, &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
}
break;
case 2:
if(in == out)
printf(“\nBuffer is Empty”);
else
{
consume = buffer[out];
OUTPUT
ALGORITHM:
Step 1: Start the Program.
Step 2: Obtain the required data through char and int datatypes.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: File is allocated to the unused index blocks.
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM: /* Bankers algorithm for Deadlock Avoidance */
#include<stdio.h>
struct process
{
int allocation[3];
int max[3];
int need[3];
int finish;
}p[10];
int main()
{
int n,i,I,j,avail[3],work[3],flag,count=0,sequence[10],k=0;
printf("\nEnter the number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the %dth process allocated resources:",i);
scanf("%d%d%d",&p[i].allocation[0],&p[i].allocation[1],&p[i].allocation[2]);
scanf("%d%d%d",&p[i].max[0],&p[i].max[1],&p[i].max[2]);
p[i].finish=0;
p[i].need[0]=p[i].max[0]-p[i].allocation[0];
p[i].need[1]=p[i].max[1]-p[i].allocation[1];
p[i].need[2]=p[i].max[2]-p[i].allocation[2];
}
printf("\nEnter the available vector:");
scanf("%d%d%d",&avail[0],&avail[1],&avail[2]); for(i=0;i<3;i++)
work[i]=avail[i];
while(count!=n)
{
count=0;
for(i=0;i<n;i++)
{
flag=1;
if(p[i].finish==0)
if(p[i].need[0]<=work[0])
if(p[i].need[1]<=work[1])
if(p[i].need[2]<=work[2])
{
for(j=0;j<3;j++)
work[j]+=p[i].allocation[j];
p[i].finish=1;
sequence[k++]=i;
flag=0;
}
if(flag==1)
count++;
}
}
count=0;
for(i=0;i<n;i++)
if(p[i].finish==1)
count++;
printf("\n The safe sequence is:\t");
if(count++==n)
for(i=0;i<k;i++)
printf("%d\n",sequence[i]);
else
printf("SYSTEM IS NOT IN A SAFE STATE \n\n");
return 0;
}
OUTPUT
$ vi bankersavoidance.c
$ cc bankersavoidance.c
$ ./a.out
Enter the number of process: 3
Enter the 0th process allocated resources: 1 2 3
Enter the 0th process maximum resources: 4 5 6
Enter the 1th process allocated resources: 3 4 5
RESULT:
Thus the program was executed and verified successfully.
EX NO: 8 DEADLOCK DETECTION
AIM:
To write a C program to implement Deadlock Detection algorithm.
ALGORITHM:
Step 1: Start the Program.
Step 2: Obtain the required data through char and in data types.
scanf("%d",&tp);
printf("enter clain matrix: \n");
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&c[i][j]);
}
}
printf("enter allocation matrix: \n");
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&p[i][j]);
}
}
printf("enter resource vector: \n");
for(i=0;i<5;i++)
{
scanf("%d",&r[i]);
}
printf("enter availability vector: \n");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=0;i<4;i++)
{
sum=0;
for(j=0;j<5;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i;
k++;
}
}
for(i=0;i<4;i++)
{
for(l=1;l<k;l++)
{
if(i!=m[l])
{
flag=1;
for(j=0;j<5;j++)
{
if(c[i][j]>temp[j])
{
flag=0;
break;
}
}
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=0;j<5;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are: \n");
for(j=0;j<tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
}
OUTPUT:
$ vi bankersdetection.c
$ cc bankersdetection.c
$ ./a.out
enter total no of processes:
0 1 0 01
0 0 1 01
0 0 0 01
1 0 1 0 1
1 0 1 1 0
1 1 0 0 0
0 0 0 1 0
0 0 0 0 0
2 1 1 2 1 enter
availability vector:
0 0 0 0 1
deadlock causing
processes are: 0 1
RESULT:
Thus the program was executed and verified successfully.
EX NO: 9 THREADING
AIM:
To Write C programs to demonstrate threading.
ALGORITHM:
Step 1: Start the process
Step 2: Declare process thread, thread-id.
PROGRAM :
#include<pthread.h>
#include<stdio.h>
#define NUM_THREADS 3
int je,jo,evensum=0,sumn=0,oddsum=0,evenarr[50],oddarr[50];
int i,n;
je=0;
n=(int)threadid;
for(i=1;i<=n;i++)
{
if(i%2==0)
{
evenarr[je]=i;
evensum=evensum+i;
je++;
}
}
}
void *Odd(void *threadid)
{
int i,n;
jo=0;
n=(int)threadid;
for(i=0;i<=n;i++)
{
if(i%2!=0)
{
oddarr[jo]=i;
oddsum=oddsum+i;
jo++;
}
}
}
void *SumN(void *threadid)
{
int i,n;
n=(int)threadid;
for(i=1;i<=n;i++)
{
sumn=sumn+i;
}
}
int main()
pthread_tthreads[NUM_THREADS];
int i,t;
printf("Enter a number\n");
scanf("%d",&t);
pthread_create(&threads[0],NULL,Even,(void *)t);
pthread_create(&threads[1],NULL,Odd,(void *)t);
pthread_create(&threads[2],NULL,SumN,(void *)t);
for(i=0;i<NUM_THREADS;i++)
{
pthread_join(threads[i],NULL);
for(i=0;i<je;i++)
printf("%d\n",evenarr[i]);
printf("The first N odd natural nos is --- \n");
for(i=0;i<jo;i++)
printf("%d\n",oddarr[i]);
pthread_exit(NULL);
}
OUTPUT:
$ vi threadf.c
$ cc threadf.c -pthread
$ ./a.out
Enter a number 12
4
6
8
10
12
The first N odd natural nos is----
1
3
5
7
9
11
RESULT:
Thus the program was executed and verified successfully.
EX NO: 10 PAGING TECHNIQUES
AIM:
To write a C program to implement paging concept for memory management.
ALGORIHTM:
Step 3: Enter the page table which has offset and page frame.
Step 4: The corresponding physical address can be calculate by, PA = [
pageframe* No. of page size ] + Page offset.
Step 5: Print the physical address for the corresponding logical address.
Step 6: Terminate the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
int s[10], fno[10][20];
clrscr();
printf("\nEnter the memory size -- ");
scanf("%d",&ms);
printf("\nEnter the page size -- ");
scanf("%d",&ps);
nop = ms/ps;
printf("\nThe no. of pages available in memory are -- %d ",nop);
printf("\nEnter number of processes -- ");
scanf("%d",&np);
rempages = nop;
for(i=1;i<=np;i++)
{
scanf("%d",&s[i]);
if(s[i] >rempages)
{
printf("\nMemory is Full");
break;
}
else
{
pa=fno[x][y]*ps+offset;
OUTPUT
Enter the memory size – 1000
Enter the page size -- 100
The no. of pages available in memory are 10
Memory is Full
Enter Logical Address to find Physical Address Enter process no. and pagenumber
and offset –
2
60
ALGORITHM:
3. Get the choices from the user and call the corresponding switch cases.
4. First fit -allocate the process to the available free block match with the size of the process
5. Worst fit –allocate the process to the largest block size available in the list
6. Best fit-allocate the process to the optimum size block available in the list
PROGRAM:
WORST-FIT
#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");
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]);
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();
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 1 5 4
2 4 3 7 3
5.3.2 BEST-FIT
#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;
{
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\tFragment");
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();
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 2 2 1
2 4 1 5 1
5.3.3 FIRST-FIT
#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;
clrscr();
scanf("%d",&nb);
scanf("%d",&nf);
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
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++)
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();
INPUT
Block 1: 5
Block 2: 2
Block 3: 7
File 1: 1
File 2: 4
OUTPUT
1 1 3 7 6
2 4 1 5 1
RESULT:
ALGORITHM:
4. Check the need of replacement from old page to new page in memory
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
if(m[k]==rs[i])
break;
}
if(k==f)
{
m[count++]=rs[i];
pf++;
}
for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF No. %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of Page Faults using FIFO are %d",pf);
getch();
OUTPUT
7 -1 -1 PF No. 1
7 0 -1 PF No. 2
7 0 1 PF No. 3
2 0 1 PF No. 4
2 0 1
2 3 1 PF No. 5
2 3 0 PF No. 6
4 3 0 PF No. 7
4 2 0 PF No. 8
4 2 3 PF No. 9
0 2 3 PF No. 10
0 2 3
0 2 3
0 1 3 PF No. 11
0 1 2 PF No. 12
0 1 2
0 1 2
7 1 2 PF No. 13
7 0 2 PF No. 14
7 0 1 PF No. 15
RESULT:
Thus the program was executed and verified successfully
LRU page replacement algorithm
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
{
scanf("%d",&rs[i]); flag[i]=0;
}
printf("Enter the number of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is -- \n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
next++;
}
}
if(flag[i]==0)
{
if(i<f)
{
m[i]=rs[i];
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
min=j;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
if(flag[i]==0)
printf("PF No. -- %d" , pf);
printf("\n");
}
printf("\nThe number of page faults using LRU are %d",pf);
getch();
}
OUTPUT
7 -1 -1 PF No. -- 1
7 0 -1 PF No. -- 2
7 0 1 PF No. -- 3
2 0 1 PF No. -- 4
2 0 1
2 03 PF No. -- 5
2 0 3
4 03 PF No. -- 6
4 02 PF No. -- 7
4 32 PF No. -- 8
0 32 PF No. -- 9
0 3 2
0 3 2
1 32 PF No. -- 10
1 3 2
1 02 PF No. -- 11
1 0 2
1 0 7 PF No. -- 12
1 0 7
1 0 7
RESULT:
Thus the program was executed and verified successfully
LFU page replacement algorithm
AIM:
ALGORITHM
Step3; Get the frame size and reference string from the user
Step5: Accommodate a new element look for the element that is not to be
used in frequently replace.
Step6: Count the number of page fault and display the value
PROGRAM
#include<stdio.h>
#include<conio.h>
main()
for(i=0;i<m;i++)
scanf("%d",&rs[i]);
printf("\nEnter the available no. of frames -- ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
cntr[i]=0;
a[i]=-1;
}
Printf(“\nThe Page Replacement Process is – \n“);
for(i=0;i<m;i++)
{
for(j=0;j<f;j++)
if(rs[i]==a[j])
{
cntr[j]++;
break;
}
if(j==f)
{
min = 0;
for(k=1;k<f;k++)
if(cntr[k]<cntr[min])
min=k;
a[min]=rs[i];
cntr[min]=1;
pf++;
}
printf("\n");
for(j=0;j<f;j++)
printf("\t%d",a[j]);
if(j==f)
printf(“\tPF No. %d”,pf);
}
printf("\n\n Total number of page faults -- %d",pf);
getch();
}
OUTPUT
Enter number of page references -- 10
Enter the reference string -- 123452525143
Enter the available no. of frames 3
The Page Replacement Process is –
1 -1 -1 PF No. 1
1 2 -1 PF No. 2
1 2 3 PF No. 3
4 2 3 PF No. 4
5 2 3 PF No. 5
5 2 3
5 2 3
5 2 1 PF No. 6
5 2 4 PF No. 7
5 2 3 PF No. 8
Total number of page faults -- 8
RESULT:
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the count, file name, graphical interface.
PROGRAM:
#include<stdio.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
{
int i,ch;
charf[30];
clrscr();
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
switch(ch)
{
case 1: printf("\nEnter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++; break;
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
{
if(strcmp(f, dir.fname[i])==0)
{
dir.fcnt--;
break;
case 3:printf("\nEnter 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("\nDirectory Empty");
else
{
}
break;
default: exit(0);
}
}
getch();
}
OUTPUT:
RESULT:
Thus the program was executed and verified successfully
Two level directory.
AIM:
To write C program to organize the file using two level directory.
ALGORITHM:
PROGRAM:
#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];
clrscr();
dcnt=0;
while(1)
scanf("%d",&ch);
switch(ch)
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
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)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
goto jmp;
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)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
goto jmp1;
goto jmp1;
jmp1: break;
case 5: if(dcnt==0)
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);
getch();
OUTPUT:
4. Create Directory 2. Create File 3. Delete 4.File Search File 5. Display 6. Exit
1. Create Directory 2. Create File 3. Delete File 4.Search File 5. Display 6. Exit
RESULT:
Thus the program was executed and verified successfully
Sequential file for processing the student information
AIM:
To write a C program for sequential file for processing the student information.
ALGORITHM:
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.
PROGRAM:
#include<stdio.h>
#include<graphics.h>
struct tree_element
char name[20];
};
Int gd=DETECT,gm;
node *root;
root=NULL;
clrscr();
create(&root,0,"root",0,639,320);
clrscr();
initgraph(&gd,&gm,"c:\tc\BGI");
display(root);
getch();
closegraph();
int i, gap;
if(*root==NULL)
(*root)=(node *)malloc(sizeof(node));
fflush(stdin);
gets((*root)->name);
scanf("%d",&(*root)->ftype);
(*root)->level=lev;
(*root)->y=50+lev*50;
(*root)->x=x;
(*root)->lx=lx;
(*root)->rx=rx;
for(i=0;i<5;i++)
(*root)->link[i]=NULL;
if((*root)->ftype==1)
gap=rx-lx;
else
gap=(rx-lx)/(*root)->nc;
for(i=0;i<(*root)->nc;i++)
create(&((*root)>link[i]),lev+1,(*root)>name,lx+gap*i,lx+gap*i+gap,lx+gap*i+gap/2);
else
(*root)->nc=0;
display(node *root)
int i;
settextstyle(2,0,4);
settextjustify(1,1);
setfillstyle(1,BLUE);
setcolor(14);
if(root !=NULL)
for(i=0;i<root->nc;i++)
line(root->x,root->y,root->link[i]->x,root->link[i]->y);
if(root->ftype==1)
bar3d(root->x-20,root->y-10,root->x+20,root>y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
for(i=0;i<root->nc;i++)
display(root->link[i]);
}}
INPUT
No of subdirectories/files(for ROOT): 2
No of subdirectories/files(for USER1): 1
No of subdirectories/files(for SUBDIR1): 2
No of subdirectories/files(for JAVA): 0
No of subdirectories/files(for VB): 0
Enter Name of dir/file(under ROOT): USER2
No of subdirectories/files(for USER2): 2
No of subdirectories/files(for SUBDIR2): 2
No of subdirectories/files(for PPL): 2
No of subdirectories/files(for AI): 2
RESULT:
Thus the program was executed and verified successfully.
EX NO: 14 FILE ALLOCATION STRATEGIES
EX.NO:14 A SEQUENTIAL FILE ALLOCATION
ALGORITHM:
b). Check whether the required locations are free from the selected
Step 5: Print the results fileno, length , Blocks allocated. Step 6: Stop the progr
PROGRAM
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
scanf("%d",&c);
if(c==1)
gotoX;
else
exit();
getch();
}
OUTPUT
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
RESULT:
Thus the program was executed and verified successfully
EX.NO:14 B INDEXED FILE ALLOCATION
ALGORITHM:
Step 1: Start the Program
PROGRAM
#include<stdio.h>
int f[50],i,k,j,inde[50],n,c,count=0,p;
main()
{
clrscr();
for(i=0;i<50;i++)
f[i]=0;
printf("enter index block\t");
scanf("%d",&p);
if(f[p]==0)
{
f[p]=1;
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
scanf("%d",&c);
if(c==1)
goto x;
else
exit();
getch();
}
OUTPUT:
Allocated
9-> 2:1
9->3:1
RESULT:
Thus the program was executed and verified successfully
EX.NO:14 C LINKED FILE ALLOCATION
ALGORITHM:
PROGRAM:
#include<stdio.h>
main()
{
int f[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}
}
printf("\n If u want to enter one more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch( );
}
Output:
Enter how many blocks are already allocated 3
3-> 1
6->1
11->1
12->1
RESULT:
Thus the program to implement the linked file allocation was executed successfully
EX NO: 15 DISK SCHEDULING ALGORITHMS
AIM:
Write a C program to simulate disk scheduling algorithms
PROGRAM
#include<stdio.h>
main()
{
int t[20], n, I, j, tohm[20], tot=0;
float avhm;
clrscr();
tohm[i]=t[i+1]-t[i];
if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}
for(i=1;i<n+1;i++)
tot+=tohm[i];
avhm=(float)tot/n;
printf(“Tracks traversed\tDifference between tracks\n”); for(i=1;i<n+1;i++)
printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);
printf("\nAverage header movements:%f",avhm);
getch();
}
OUTPUT
70 10
18 52
90 72
150 60
160 10
184 24
#include<stdio.h>
main()
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}
}
}
for(i=0;i<n+2;i++)
if(t[i]==h)
j=i;k=i;
p=0;
while(t[j]!=0)
{
atr[p]=t[j];
j--;
p++;
}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverage header movements:%f",(float)sum/n);
getch();
}
OUTPUT
Enter no.of tracks:9
1841 24
90 94
70 20
60 10
58 2
55 3
18 37
#include<stdio.h>
main()
{
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0;
clrscr();
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}
for(i=0;i<=n+2;i++)
if(t[i]==h)
j=i;
break;
p=0;
while(t[j]!=tot-1)
{
atr[p]=t[j];
j++;
p++;
}
atr[p]=t[j];
p++;
i=0;
while(p!=(n+3) && t[i]!=t[h])
{
atr[p]=t[i];
i++;
p++;
}
for(j=0;j<n+2;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("total header movements%d",sum);
printf("avg is %f",(float)sum/n);
getch();
}
OUTPUT
Enter the track position: 55 58 60 70 18 90 150 160 184
Enter starting position : 100
Tracks traversed Difference Between tracks
150 50
160 10
184 24
18 240
55 37
58 3
60 2
70 10
90 29
RESULT:
Thus the program to implement disk Scheduling algorithm has been executed and verified.