0% found this document useful (0 votes)
4 views96 pages

Os Record

The document outlines the practical work for a Computer Applications course for the academic year 2024-2025, including various programming exercises related to operating systems. It covers topics such as basic UNIX commands, CPU scheduling algorithms, file allocation strategies, and synchronization techniques. Each section includes aims, algorithms, coding examples, and results confirming successful execution of the programs.

Uploaded by

mthamarai648
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)
4 views96 pages

Os Record

The document outlines the practical work for a Computer Applications course for the academic year 2024-2025, including various programming exercises related to operating systems. It covers topics such as basic UNIX commands, CPU scheduling algorithms, file allocation strategies, and synchronization techniques. Each section includes aims, algorithms, coding examples, and results confirming successful execution of the programs.

Uploaded by

mthamarai648
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/ 96

AGARAM VILLAGE, ARNI TALUK,

T.V.MALAI DISTRICT – 632 316.

DEPARTMENT OF COMPUTER
APPLICATION
2024-2025
OPERATING SYSTEM LAB

SUBMITTED BY

REG.NO :

NAME :

SUB.CODE :

CLASS : III -YEAR B.Sc(CS)


AGARAM VILLAGE, ARNI TALUK, T.V.MALAI DISTRICT – 632 316.

BONAFIDE CERTIFICATE

DEPARTMENT OF COMPUTER APPLICATIONS

B.C.A

Certified that this is a bonafide record of the practical work done by

Mrs/Miss. With Reg.No

Submitted for Practical Examination

held on in this Department during the academic year 2024-2025.

Head of the Department Staff In-charge

Internal Examiner External Examiner


INDEX

S.No DATE CONTENTS PageNo Signature

1 BASIC UNIX COMMANDS

2 SHELL PROGRAMMING

3 CPU SCHEDLING ALGORITHM


a)ROUND ROBIN b)SJF c)FCFS d)PRIORITY

4 FILE ALLOCATION STRATEGIES


a)SEQUANTIAL b)INDEXED c)LINKED

5 SEMAPHORES

FILE ORGANIZATION TECHNIQUES


6 a) SINGLE-LEVEL DIRECTORY
b) TWO-LEVEL DIRECTORY
c) HIERARCHICAL DIRECTORY d) DAG

BANKERS ALGORITHM FOR DEADLOCK


7
AVOIDANCE

8 DEADLOCK DETECTIONS

PAGE REPLACEMENT ALGORITHM


9
a)FIFO b)LRU c)LFU

10 SHARED MEMORY AND IPC

PAGING TECHNIQUE OF MEMORY


11
MANAGEMENT

THREADING A

SYNCHORNIZATION
12
APPLICATIONS
Ex. No: 1
BASICUNIX COMMANDS
Date:

AIM:
To write a basic commands in Linux

CODING:
1) date

Output: Saturday 01 October 2022 10:09:59 AMIST

2) cal

Output: October 2022

Su Mo Tu We Th Fr Sa
1

2 34 5 6 7 8
9 101112 13 1415

16 1718 19 20 21 22
23 2425 26 27 28 29
30 31

3) Echo

Echo “text”
Output: text

4) Hostname

Output: ubuntu

5)rm

Syn:rm filename
Output: remove file

6)touch

Syn: Touch file name


Output: create blank files

7) cp(copies)
Syn: cp source file to destination file
Output: cp filename

8) mv(rename)
Syn: mv old file to new file

Output: mv file name

9) more
Syn: more file name

10) clear
Syn:clear
Output: clear the current screen

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.No:2
SHELL PROGRAMMING
Date:

AIM:
To write a shell program for factorial

ALGORITHM:

Step-1:Start the program

Step-2:Ask the user to enter an integer to find the factorial

Step-3:Read the integer and assign it to a variable

Step-4:From the value of the integer upto1, multiply each digit and update the final value

Step-5:The final value at the end of all the multiplication till 1 is the factorial

Step-6:Stop the program


CODING:
Echo “enter the number”

Read num
Fact=1
While[$num-gt1] Do
Fact=$((fact*num))
Fact=$((num-1))

Done
Echo $fact

OUTPUT:
Enter the number:5

120

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 3(a)
ROUND ROBIN SCHEDULING
Date:

AIM:
To write a program for Round Robin scheduling

ALGORITHM:
Step-1:Start the program

Step-2:Declarethevariable

Step-3:Get the date from the user

Step-4:Schedule the process based on the time slice

Step-5:Print the round robin scheduling

Step-6:Stop the program


CODING:
#include<stdio.h>v

oid main()
{
inti,n,pid[15],bst[15],wait=0,tarnd,ts;
printf("\n Enter the no of process:");
scanf("%d",&n);
printf("\nEnter the values:");

for(i=1;i<=n;i++)
{
printf("\nEnter the process id:");
scanf("%d",&pid[i]);
printf("\n Enter the burst time:");

scanf("%d", &bst[i]);
}
printf("\n Enter the value for time slice:");
scanf("%d",&ts);
printf("\npid\tburst\twait\ttarnd");

for(i=1;i<=n;i++)
{
if(bst[i]>ts)
{
n=n+1;
bst[n]=bst[i]-ts;

bst[i]=bst[i]-bst[n];
pid[n]=pid[i];
}
tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d\t",pid[i],bst[i],wait,tarnd);

wait=tarnd;
}
}
OUTPUT:
Enterthenoofprocess:3

Enter the values:


Entertheprocessid:1
Enter the burst time:6
Enter the process id:2

Enter the burst time:5


Enter the process id:3

Enter the burst time:4


Enter the value for time slice:4
pid burst wait tarnd
1 4 0 4
2 4 4 8

3 4 8 12
1 2 12 14

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 3(b)
SJF SCHEDULING
Date:

AIM:
To write a program for shortest job first algorithm

ALGORITHM:
Step-1:Start the program

Step-2:Declarethevariable

Step-3:Get the required data using for loop

Step-4:Check the shortest job in the list

Step-5:Print the shortest job

Step-6:Stop the program


CODING:
#include<stdio.h>v

oid main()
{
int i,n,j,pid[20],bst[20],wait=0,tarnd,t;
printf("\n enter the number of process:");
scanf("%d",&n);
for (i=1;i<=n;i++)

{
printf("enter the process id:");

scanf("%d",&pid[i]);
printf("\n enter the burst time:");
scanf("%d",&bst[i]);

}
printf("\npid\tburst\twait\ttarnd"); for
(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)

{
if(bst[i]>bst[j])
{
t=bst[i];
bst[i]=bst[j];
bst[j]=t;

t=pid[i];
pid[i]=pid[j];
pid[j]=t;
}
}

}
for(i=1;i<=n;i++)
{
tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d",pid[i],bst[i],wait,tarnd); wait=tarnd;

}
}

OUTPUT:
Enter the number of
process:5

enter the process id:1


enter the burst time:9
enter the process id:2
enter the burst time:7

enter the process id:3


enter the burst time:5

enter the process id:4


enter the burst time:3

enter the process id:5


enter the burst time:1
pid burst wait tarnd
5 1 0 1
4 3 1 4
3 5 4 9
2 7 9 16
1 9 16 25
RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 3(c)
FCFS SCHEDULING

Date:

AIM:
To write the program for First Come First serves scheduling

ALGORITHM:
Step-1:Start the program

Step-2:Declarethevariable

Step-3:Get the required values using a for loop

Step-4:Printtheturnaroundtimeusingaaddition

Step-5:Stop the program


CODING:

#include<stdio.h>v

oid main()
{
inti,n,pid[5],bst[5],wait=0,tarnd;

printf("\nEnter the number of process id");


scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the process id:\n");
scanf("%d",&pid[i]);
printf("Enter the burst time;");

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

}
printf("\npid\tburst\twait\ttarnd");
for(i=1;i<=n;i++)
{

tarnd=wait+bst[i];
printf("\n%d\t%d\t%d\t%d",pid[i],bst[i],wait,tarnd); wait=tarnd;
}
}
OUTPUT:

Enterthenumberofprocessid:5

Enter the process id:1

Enterthebursttime:5
Entertheprocessid:2
Enterthebursttime:5
Entertheprocessid:3
Enterthebursttime:5
Entertheprocessid:4
Enterthebursttime:5
Entertheprocessid:5
Entertheburst time:5

pid burst wait tarnd


1 5 0 5
2 5 5 10
3 5 10 15

4 5 15 20
5 5 20 25

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.No:3(d)
PRIORITYSCHEDULING
Date:

AIM:
To write a program for Priority scheduling

ALGORITHM:
Step-1:Start the program

Step-2:Declare the variable

Step-3:Get the data from the user

Step-4:Find out the average burst time and turnaround

time Step-5:Enter the priority based process

Step-6:Print the average burst time and turnaround time

Step-7:Stop the program


CODING:
#include<stdio.h>v

oid main()
{
intbt[20],p[20],wt[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat,tat[20];
printf("enter the number of process:");
scanf("%d",&n);

printf("enter 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];
pr[pos]=temp;
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\tbursttime\twaitingtime\tturnaroundtime");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\np[%d]\t%d\t%d\t%d\t",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n;
printf("\n Average Waiting time=%d",avg_wt);

printf("\nAverage turnaround time=%d",avg_tat);


}
OUTPUT:

Enter the number of process:4


Enter burst time and priority:
p[1]
burst time:2
priority:3
p[2]
burst time:4
priority:6
p[3]

burst time:7
priority:5
p[4]

burst time:6
priority:4
process burst time waiting time turnaround time
p[1] 2 0 2
p[4] 6 2 8

p[3] 7 8 15
p[2] 4 15 19

Average Waiting time=6


Average turnaround time=11

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.No:4(a) FILE ALLOCATION STRATEGIES
SEQUANTIAL FILE

Date:

AIM:

To implement sequential file allocation techniques

ALGORITHM:

Step-1:Start the program

Step-2:Get the number of files

Step-3:Get the memory requirements of each file

Step-4: Allocate the required locations to each is sequential order


a)randomly select a location from available locationS1=random(100);

b) check whether the required location are from the selected location c)

allocated and set flag=1 to the allocated location

Step-5: Print the results file no, length, blocks allocated

Step-6: Stop the program


CODING:
#include<stdio.h>

#include<stdlib.h>

void main()

intf[50],i,st,j,len,c,k;

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

f[i]=0;

x:

printf("\n enter the starting block and 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("\nthe file is allocated to disk");

printf("\n if you want to enter more files?(y-1/n-0)");

scanf("%d",&c);

if(c==1)

goto x;

elseexit;
}

OUTPUT:

Enter the starting block and length of file :3 10

3->1

4->1

5->1

6->1

7->1

8->1

9->1

10->1

11->1

12->1

The file is allocated to disk

If you want to enter more files?(y-1/n-0):0

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 4(b) FILE ALLOCATION STRATEGIES
INDEXED FILE

Date:

AIM:
To write a program for file allocation concept using Indexed allocation techniques

ALGORITHM:
Step-1:Start the program

Step-2:Get the number of files

Step-3:Get the memory requirement of each file

Step-4:Allocate the required location by selecting allocation

randomly

Step-5:Print the results file number length ,blocks allocated

Step-6:Stop the program


CODING:
#include<stdio.h>v

oid main()
{
intf[50],i,k,j,inde[50],n,c,count=0,p;
for(i=0;i<50;i++)
f[i]=0;
x:

printf("enter index block\n");


scanf("%d",&p);
if(f[p]==0)
{
f[p]=1;

printf("enter no of files on index");


scanf("%d",&n);
}
else
{

printf("Block already allocated\n");

goto x;
}
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)

if(f[inde[i]]==1)

{
printf("Block already allocated");
goto x;
}

for(j=0;j<n;j++)
f[inde[j]]=1;
printf("\n allocated");
printf("\n file indexed");

for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
printf("enter 1 to enter more file and to exit\t");
scanf("%d",&c);

if(c==1)
goto x;
}

OUTPUT:
Enter index block:5
Enter no of files on index:4

6
7

8
9
allocated
file indexed
5->6:1
5->7:1

5->8:1
5->9:1

Enter 1 to enter more file and 0 to exit:: 0


RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 4(c) FILE ALLOCATION STRATEGIES
LINKED FILE

Date:

AIM:

To write a program for file allocate concept using linked list technique

ALGORITHM:
Step-1:Start the program

Step-2:Get the number of files

Step-3:Allocate required location by selecting allocation randomly

Step-4:Check whether the selected location free

Step-5:If the location is free allocated and set flag=1totheallocatedlocation

Step-6:Print the result file no, length, blocks allocated

Step-7:Stop the program


CODING:
#include<stdio.h>

void main()
{
intf[50],p,i,j,k,a,st,len,n,c;
for(i=0;i<50;i++)
f[i]=0;

printf("\n Enter how many blocks that arealready allocated");


scanf("%d",&p);

printf("\n Enter the blocks no.s print are already allocated");


for(i=0;i<p;i++)
{
scanf("%d",&a);

f[a]=1;
}
x:
printf("\n Enter the starting index block & length");
scanf("%d%d",&st,&len);

k=len;
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 you want to enter one more file?(yes-1/no-0)");

scanf("%d",&c);
if(c==1)

goto x;
}

OUTPUT:

Enterhowmanyblocksthatarealreadyallocated:3
Enter the blocks no.s print are already allocated:68
10
Enterthestartingindexblock&length:310 3-

>1
4->1
5->1
6->file is already allocated

7->1
8->file is already allocated
9->1
10->file is already allocated
11->1
12->1
13->1

14->1
15->1
If you want to enter on file?(yes-1/no-0):0
RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.No:5
SEMAPHORES

Date:

AIM:

To write a program for producer consumer problem

ALGORITHM:
Step-1:Start the program

Step-2:Declare the variable

Step-3:Get producer name from user

Step-4:Sale the products one by one

Step-5:Print the message

Step-6:Stop the program


CODING:
#include<stdio.h>v

oid main()
{
intn,a[5],in,out,pr,cr,ch;
in=out=pr=cr=0;
printf("\n Enter the no of element:");
scanf("%d",&n);
do
{
printf("\n1.proceducer\n2.customer\n3.exit:");
printf("\n Enter the choice:");scanf("%d",&ch);
switch(ch)
{
case 1:
if(in>=n)
printf("\n The Buffer is overflowing");

else
{
pr=1;
in++;
printf("\n Enter the element:");
scanf("%d",&a[in]);

if(in==n)
pr=0;
}
break;

case2:
if(in==out)
printf("\n The buffer is under flowing:"); else if(pr==1)
printf("\nThe Producer process is going on:");

else
{

cr=1;
printf("\nThe element %d is consumer:",a[in]);
in--;
if(in==0)
cr=0;
}
break;
}
}
while(ch!=3);

OUTPUT:
Enterthenoofelement:3

1.proceducer

2.customer
3.exit:

Enter the choice:1


Enter the element:20

1.proceducer
2.customer

3.exit:

Enter the choice:1


Entertheelement:40
1.proceducer
2.customer
3.exit:

Enter the choice:1


Enter the element:56

1.proceducer
2.customer

3.exit:

Enterthechoice:1
The Buffer is overflowing
1.proceducer
2.customer
3.exit:

Enterthechoice:2
The element 56 is consumer:

1.proceducer
2.customer

3.exit:

Enterthechoice:2

The element 40 is consumer:


1.proceducer
2.customer

3.exit:

Enterthechoice:2

The element 20 is consumer:


1.proceducer

2.customer
3.exit:
Enter the choice:2
The buffer is under flowing

1.proceducer
2.customer
3.exit:
Enterthechoice:3

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 6 FILE ORGANIZATION TECHNIQUES
a) Single-level directory
Date:

AIM:

To write a program for file organization techniques using single–level directory

ALGORITHM:

Step1:Start the Program

Step2:Initializevaluesgd=DETECT, gm, count, i, j, mid, cir_x.

Step 3: Initialize graph function

Step4:Set background color with set bkcolor();

Step 5: Read number of files in variable count.

Step 6: check i; mid=640/count;

Step-7:stop the program


CODING:

#include<stdio.h>

struct

chardname[10],fname[10][10];

int fcnt;

}dir;

void main()

int i,ch;

char f[30];

clrscr();

dir.fcnt=0;

printf("\nEnter name of directory--");

scanf("%s", dir.dname);

while(1)

printf("\n\n1.Create File\t2.DeleteFile\t3.SearchFile\n4.DisplayFiles\t5.Exit\nEnteryourchoice--");

scanf("%d",&ch);

switch(ch)

case1:printf("\nEnter the name of the file--");

scanf("%s",dir.fname[dir.fcnt]);

dir.fcnt++;

break;

case2: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 deleted ",f);

strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);

break;

if(i==dir.fcnt)

printf("File%snotfound",f);

else

dir.fcnt--;

break;

case3: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%sisfound",f);

break;

if(i==dir.fcnt)

printf("File%snotfound",f);

break;

case 4: if(dir.fcnt==0)

printf("\nDirectory Empty");

else

printf("\nThe Files are--");

for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);

break;

default: exit(0);

getch();

OUTPUT:

Enter name of directory --CSE

1.Create File2.Delete File3.Search File

4.Display Files 5.Exit Enteryourchoice–1

Enter the name of the file -- A

1.Create File2.Delete File3.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.CreateFile 2.DeleteFile 3.SearchFile

4. Display Files 5.Exit Enteryourchoice–3

Enter the name of the file–ABC

File ABC not found

1.CreateFile 2.DeleteFile 3.SearchFile

4.DisplayFiles 5.Exit Enter your choice–2

Enter the name of the file–B

File B is deleted

1.CreateFile 2.DeleteFile 3.SearchFile

4.DisplayFiles 5.Exit Enter your choice–5

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.No: 6(b) FILE ORGANIZATION TECHNIQUES
b) TWO-LEVEL DIRECTORY

Date:

AIM:
To write a program file organization techniques using Two–level directory

ALGORITHM:

Step-1:Start the Program

Step-2:Initialize structure elements

Step-3: Start main function

Step-4:Setvariablesgd=DETECT, gm;

Step-5:Create structure using create(&root,0,”null”,0,639,320);

Step-6: init graph(&gd,&gm,”c:\tc\bgi”);

Step-7:Stop the program


CODING:
#include<stdio.h>

struct

chardname[10],fname[10][10];

int fcnt;

}dir[10];

voidmain()

int i,ch,dcnt,k;

charf[30],d[30];

clrscr();

dcnt=0;

while(1)

printf("\n\n 1. Create Directory\t 2. Create File\t 3. Delete File");

printf("\n4.Search File\t \t5.Display \t6.Exit\tEnter your choice--");

scanf("%d",&ch);

switch(ch)

case1:printf("\n Enter name of directory--");

scanf("%s", dir[dcnt].dname);dir[dcnt].fcnt=0;

dcnt++;

printf("Directory created");

break;

case2: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;

case3: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;

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

getch();

OUTPUT:
1.CreateDirectory 2.CreateFile 3.DeleteFile

4.SearchFile 5.Display 6.Exit Enter your choice--1

Enter name of directory--DIR1

Directory created

1. Create Directory 2.Create File3.Delete File

4. Search File 5.Display 6.Exit Enter your choice--1

Enter name of directory -- DIR2

Directory created
1.CreateDirectory 2.CreateFile 3.DeleteFile

4.SearchFile 5.Display 6.Exit Enteryour choice--2

Enter name of the directory–DIR1

Enter name of the file -- A1

File created

1.CreateDirectory 2.CreateFile 3.DeleteFile

4.SearchFile 5.Display 6.Exit Enteryour choice--2

Enter name of the directory–DIR1

Enter name of the file -- A2

File created

1.CreateDirectory 2.CreateFile 3.Delete File

4.SearchFile 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.CreateFile 3.DeleteFile

4.Search File 5.Display 6.Exit Enter your choice--5

Directory Files

DIR1A1A2

DIR2 B1

1.Create Directory 2.CreateFile 3.DeleteFile

4.SearchFile 5.Display 6.Exit Enter your choice--4

Enter name of the directory –DIR


Directory not found

1.Create Directory 2.CreateFile 3.Delete File

4.SearchFile 5.Display 6.ExitEnteryourchoice --3

Enter name of the directory – DIR1

Enter name of the file-- A2

FileA2is deleted

1.CreateDirectory 2.CreateFile 3.DeleteFile

4.SearchFile 5.Display 6.ExitEnter your choice–6

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No: 6(c) FILE ORGANIZATION TECHNIQUES
c)HIERARCHICAL DIRECTORY

Date:

AIM:

To write a C program File Organization concept using the technique hierarchical level directory.

ALGORITHM:

Step1:Start the Program

Step2:Define structure and declare structure variables

Step 3: start main and declare variables

Step4:Check a directory tree structure

Step5:Display the directory tree in graphical mood

Step 6: Stop the program


CODING:

#include<stdio.h>

#include<graphics.h>str

uct tree_element

charname[20];

int x,y,ftype,lx,rx,nc,level;

structtree_element*link[5];

};

Typedef structtree_element

node; void main()

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

create(node**root,intlev,char*dname,intlx,intrx,intx)

int i,gap;

if(*root==NULL)

(*root)=(node *)malloc(sizeof(node));

printf("Enter name of dir/file(under%s):",dname);


fflush(stdin);

gets((*root)->name);

printf("enter1forDir/2forfile:");

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)

printf("Noofsubdirectories/files(for%s):",(*root)->name);scanf("%d",&(*root)->nc);

if((*root)->nc==0)

gap=rx-lx;

elsegap=(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]);

}
OUTPUT:

Enter Name of dir/file(under root):ROOT

Enter 1 for Dir / 2 For File : 1

No of subdirectories / files (for ROOT) :2

Enter Name of dir/file(under ROOT):USER1

Enter 1 for Dir /2 for file:1

No of subdirectories/files(forUSER1):1

Enter Name of dir/file(underUSER1):SUBDIR

Enter 1 for Dir /2 for file:1

No of subdirectories/files(for SUBDIR):2

Enter Name of dir/file (under USER 1):

JAVA Enter 1 for Dir /2 for file:1

No of subdirectories /files (for JAVA): 0

Enter Name of dir/file(under SUBDIR):VB

Enter 1 for Dir /2 for file:1

No of sub directories/files(for VB):0

Enter Name of dir/file(under ROOT):USER2

Enter 1 for Dir /2 for file:1

No of subdirectories/files(forUSER2):2

Enter Name of dir/file (under ROOT):A

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(underUSER2):SUBDIR2

Enter 1 for Dir /2 for file:1

No of subdirectories/files(forSUBDIR2):2

Enter Name of dir/file(underSUBDIR2):PPL

Enter 1 for Dir /2 for file:1

No of subdirectories/files(for PPL):2

Enter Name of dir/file (under PPL):B


Enter1forDir/2for file:2

Enter Name of dir/file(under PPL):C

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(under SUBDIR):AI

Enter 1 for Dir /2 for file:1

No of subdirectories/files(for AI):2

Enter Name of dir/file (under AI):D

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(under AI):E

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex. No:6(d) FILE ORGANIZATION TECHNIQUES
d)DAG
Date:

AIM:
To write a C program File Organization concept using the technique DAG

ALGORITHM:

Step-1:Start the program.


Step-2:Get the name of the directories.
Step-3: get the number of files.
Step-4:Get the name of the each file.
Step-5:Now each file is in the form of fill circle
Step-6:Every file is connected with respective directory
Step-7:Display the connected graphical with name using graphics

Step-8: Stop the program


CODING:
#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<string.h>stru

ct tree_element

charname[20];

int x,y,ftype,lx,rx,nc,level;

structtree_element*link[5];

};

Typedef structtree_element

node; typedef struct

charfrom[20];

char to[20];

}link;link

L[10]; int

nofl;

node*root;

void main()

intgd=DETECT,gm;

root=NULL;clrscr();

create(&root,0,"root",0,639,320);

read_links();

clrscr();

initgraph(&gd,&gm,"c:\\tc\\BGI");

draw_link_lines();
display(root);

getch();

closegraph();

read_links()

inti;

printf("how many links");

scanf("%d",&nofl);

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

printf("File/dir:");

fflush(stdin);

gets(L[i].from);

printf("username:");

fflush(stdin);

gets(L[i].to);

draw_link_lines()

int i,x1,y1,x2,y2;

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

search(root,L[i].from,&x1,&y1);

search(root,L[i].to,&x2,&y2);

setcolor(LIGHTGREEN);

setlinestyle(3,0,1);

line(x1,y1,x2,y2);

setcolor(YELLOW);
setline style(0,0,1);

search(node*root,char*s,int*x,int*y)

int i;

if(root!=NULL)

if(strcmpi(root->name,s)==0)

*x=root->x;

*y=root->y;

return;

else

for(i=0;i<root->nc;i++)

search(root->link[i],s,x,y);

create(node**root,intlev,char*dname,intlx,intrx,intx)

int i,gap;

if(*root==NULL)

(*root)=(node*)malloc(sizeof(node));

printf("enter name of dir/file(under

%s):",dname);fflush(stdin);

gets((*root)->name);
printf("enter 1 for dir/ 2 for

file:");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)

printf("noofsubdirectories/files(for%s):",(*root)-

>name);scanf("%d",&(*root)->nc);

if((*root)->nc==0)

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;

/*displays the constructed tree in graphics

mode */ 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]);

}}}
OUTPUT:
Enter Name of dir/file(under root):ROOT

Enter 1 for Dir / 2 For File : 1

No of subdirectories / files (for ROOT) :2

Enter Name of dir/file(under ROOT):USER1

Enter 1 for Dir /2 for file:1

No of subdirectories /files (for USER 1):2

Enter Name of dir/file(underUSER1):VB

Enter 1 for Dir /2 for file:1

No of subdirectories/files(for VB):2

Enter Name of dir/file (under VB): A

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(under VB):B

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(underUSER1):C

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(under ROOT):USER2

Enter 1 for Dir /2 for file:1

No of subdirectories /files (for USER2): 1

Enter Name of dir/file(underUSER2):JAVA

Enter 1 for Dir /2 for file:1

No of subdirectories/files(for JAVA):2

Enter Name of dir/file (under JAVA):D

Enter 1 for Dir /2 for file:2

Enter Name of dir/file(under JAVA):HTML

Enter 1 for Dir /2 for file:1

No of sub directories/files(for HTML):0

How many links:2

File/Dir: B

UserName:USER2
File/Dir: HTML

UserName:USER1

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:7 BANKERS ALGORITHM FOR DEADLOCK
AVOIDANCE
Date:

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 no deadlock process otherwise it is
a deadlock process
Step-6:produce the result of state of
process
Step-7:Stop the program
CODING:
#include<stdio.h>
Intmax[20][20],all[20][20],need[20][20],avail[20];
int n,r;
Void input();
Void show();
void call();
void main()
{
int i,j;
printf("Deadlock Avoidance");
input();
show();
call();
getch();
}

Void input()
{
int i,j;
printf("Enter no of processes:");
scanf("%d",&n);
printf("Enter no of resource instances:");
scanf("%d", &r);
printf("Enter the max matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
scanf("%d", &max[i][j]);
}

printf("Enter the allocation matrix:\n");


for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
scanf("%d",&all[i][j]);
}

printf("Enter the available resources:\n");


for(j=0;j<r;j++)
scanf("%d",&avail[j]);
}

void show()
{
int i,j;
printf("Process Allocation Maximum Available\n");
for(i=0;i<n;i++)
{
printf("\nP%d:",i);
for(j=0;j<r;j++)
{
printf("%d",all[i][j]);
}
printf("\t");
for(j=0;j<r;j++)
{
printf("%d",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++)
printf("%d",avail[j]);
}
}
}

voidcall()
{
Int finish[20],temp,
need[20][20],flag=1,k,c1=0; int safe[20];
int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
need[i][j]=max[i][j]-all[i][j];
}
printf("\n");
while(flag)
{
flag=0;
for(i=0;i<n;i++)
{
int c=0;
for(j=0;j<r;j++)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{
c++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=all[i][j];
finish[i]=1;flag=1;
}
printf("P%d->",i);
if(finish[i]==1)
{
i=n;
}
} //if
}//if
} //for
} //for
} //while

for(i=0;i<n;i++)
{
if(finish[i]==1)
{
c1++;
}
}
if(c1==n)
{
printf("\n The system is in Safe State");
}
else
{
printf("\n Process are in dead lock");
printf("\nThe System is in unsafe state");
}
}

OUTPUT:

DEADLOCKAVOIDANCE
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 02
2 21
Enter the allocation matrix:

101

111

Enter the available resources:

111

Process Allocation Maximum Available

P0 : 101 102 1 11

P1: 111 321


P0->P1->

The System is in Safe State

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:8 DEADLOCK DETECTION
Date:

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
Step-6:produce the result of state of process
Step-7: Stop the program
CODING:

#include<stdio.h>
intmax[20][20],all[20][20],need[20][20],avail[20];
int n,r;
voidinput();
voidshow();
void call();

void main()
{
int i,j;
printf("Deadlock Detection");
input();
show();
call();
getch();
}

voidinput()
{
int i,j;
printf("\nEnter no of processes:");
scanf("%d",&n);
printf("Enter no of resource instances:");
scanf("%d",&r);

printf("Enter the max matrix:\n");


for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
scanf("%d",&max[i][j])
}
printf("Enter the allocation matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
scanf("%d",&all[i][j]);
}
printf("Enter the available resources:\n");
for(j=0;j<r;j++)
scanf("%d",&avail[j]);
}

void show()
{
int i,j;
printf("Process Allocation Maximum Available\n");
for(i=0;i<n;i++)
{
printf("\nP%d:",i);
for(j=0;j<r;j++)
{
printf("%d ",all[i][j]);
}
printf("\t");
for(j=0;j<r;j++)
{
printf("%d ",max[i][j]);
}
printf("\t");
if(i==0)
{
for(j=0;j<r;j++)
printf("%d ",avail[j]);
}
}
}

voidcall()
{
intfinish[20],temp,need[20][20],flag=1,k;
int dead[20],safe[20];
int i,j;
for(i=0;i<n;i++)
{
finish[i]=0;
}

for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
need[i][j]=max[i][j]-all[i][j];
}
while(flag)
{
flag=0;
for(i=0;i<n;i++)
{
int c=0;
for(j=0;j<r;j++)
{
if((finish[i]==0)&&(need[i][j]<=avail[j]))
{
c++;
if(c==r)
{
for(k=0;k<r;k++)
{
avail[k]+=all[i][j];
finish[i]=1;flag=1;
}
if(finish[i]==1)
{
i=n;
}//if
} //if
} //if
} //for
} //for
}//while
j=0;
flag=0;
for(i=0;i<n;i++)
{
if(finish[i]==0)
{
dead[j]=i;
j++;
flag=1;
}
}
if(flag==1)
{
printf("\nsystem is in deadlock and the deadlock process are \n");
for(i=0;i<n;i++)
{
printf("P%d :",dead[i]);
}
}
else
printf("\n no deadlock occur");
}

OUTPUT:
DEADLOCKDETECTION
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 11
2 12
Enter the allocation matrix:

100

201

Enter the available resources:

000

Process Allocation Maximum Available

P0 : 100 111 0 00

P1: 201 212

System is in deadlock and the deadlock processes are

P0 :P1:
RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:9(a) PAGE REPLACEMENT ALGORITHM

Date: FIFO

AIM:

To write a c program to implement Page replacement FIFO algorithm

ALGORITHM:

Step-1:Start the program.

Step-2:Read the number of pages n.

Step-3:Read the number of pages no.

Step-4:Read the pages number into an arraya[i].

Step-5:Initialize a val[i]=0 to check page hit.

Step-6:print the results.

Step-7:Stop the program.


CODING:

#include<stdio.h>v

oid main()

inta[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;

char f='F';

printf("Enter the number of pages:");

scanf("%d",&n);

printf("Enter the %d page numbers:",n);

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

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

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

if(p==0)

if(q>=3)

q=0;

a[q]=b[i];

q++;

if(q1<3)

q1=q;

printf("\n%d",b[i]);

printf("\t");

for(h=0;h<q1;h++)

printf("%d",a[h]);

if((p==0)&&(q<=3))

{
printf("-->%c",f);

m++;

p=0;

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

if(b[i+1]==a[k])

p=1;

printf("\nNo of faults:%d",m);

OUTPUT:

Enter the number of pages:10

Enterthe10 pagenumbers:1 23 45 12 34 5

1 1-->F

2 12-->F

3 123-->F

4 423-->F

5 453-->F

1 451-->F

2 251-->F

3 231-->F

4 234-->F

5 534-->F

No offaults:10
RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:9(b) PAGE REPLACEMENT ALGORITHM

Date: LRU

AIM:

To write a c program to implement the page replacement LRU algorithm

ALGORITHM:

Step-1:Start the program

Step-2: Declare the size

Step-3:Get the number of pages to be issued

Step-4:Declare counter and stack

Step-5:Select the LRU page by counter value

Step-6:Stack them according the selection

Step-7:Stop the program


CODING:

#include<stdio.h>

void main()

intg=0,a[5],b[20],p=0,q=0,m=0,n,k,i,q1=1,j,u,h;

char f='F';

printf("Enter the number of pages:");

scanf("%d",&n);

printf("Enter %d page number:",n); for(i=0;i<n;i++)

scanf("%d",&b[i]);for(i=0;i<n;i++)

if(p==0)

if(q>=3)

q=0;

a[q]=b[i];

q++;

if(q1<3)

q1=q;

printf("\n%d",b[i]);

printf("\t");

for(h=0;h<q1;h++)

printf("%d",a[h]);

if((p==0)&&(q<=3))

{
printf("-->%c",f);

m++;

p=0;

g=0;

if(q1==3)

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

if(b[i+1]==a[k])

p=1;

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

u=0;

k=i;

while(k>=(i-1)&&(k>=0))

if(b[k]==a[j])

u++;

k--;

if(u==0)

q=j;

else

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

if(b[i+1]==a[k])

p=1;

printf("\nno.fault:%d",m);

OUTPUT:

Enter the number of pages:12

Enter12 pagenumber:2 32 1 52 45 32 3 2

2 2-->F

3 23-->F

2 23

1 231-->F

5 251-->F

2 251

4 254-->F

5 254

3 354-->F

2 352-->F

3 352

2 352

no.fault:7
RESULTS:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:9(c) PAGE REPLACEMENT ALGORITHM

Date: LFU

AIM:

To write a c program to implement Page replacement LFU algorithm

ALGORITHM:

Step-1:Start the program

Step-2:Read Number Of Pages And Frames

Step-3;.Read Each Page Value

Step-4:Search For Page In The Frames

Step-5:If Not Available Allocate Free Frame

Step-6:If No Frames Is Free Replace The Page With The Page That Is Least Used

Step-7:Print Page Number Of Page Faults

Step-8:Stoptheprogram
CODING:

#include<stdio.h>v

oid main()

intrs[50],i,j,k,m,f,cntr[20],a[20],min,pf=0;

printf("Enter no.of page reference--");

scanf("%d",&m);

printf("\nEnter the reference string--");

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("\nEnter page replacement process is--");

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("\tPFno%d",pf);

printf("\nTotal no of page faults:%d",pf);

OUTPUT:

Enter no.of page reference--12

Enter the reference string--123452525143

Enter the available no of frames--3

Enter page replacement process is--

1 -1 -1 PFno1

1 2 -1 PFno2

1 2 3 PFno3

4 2 3 PFno4

5 2 3 PFno5

5 2 3 PFno5

5 2 3 PFno5
5 2 3 PFno5
5 2 3 PFno5

5 2 1 PFno6

5 2 4 PFno7

5 2 3 PFno8

Total no of page faults:8

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:10 SAHRED MEMORIES AND IPC

Date:

AIM:

To write a program for shared memory and IPC

ALGORITHM:

Step-1:Start the program

Step-2:Declare the variable in the structure

Step-3:Declare the variable in main

function Step-4:Get the values for the

variables

Step-5:Get the data from the user

Step-6:Print the data received from the user

Step-7:Stop the program


CODING:

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/shm.h>

#include<string.h>vo

id 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("enter some data to write to shared memory\n");

read(0,buff,100);

strcpy(shared_memory,buff);

printf("you wrote:%s\n",(char*)shared_memory);

OUTPUT:

Key of shared memory is 60

Process attached at

0x7f1bf34b3000

Enter some data to write to shared memory

Hello World

You wrote: Hello World


RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:11 PAGINGTECHNIQUEOFMEMORYMANAGEMENT

Date:

AIM:

To write a c program to implement the concept of paging

ALGORITHM:

Step-1:Start the program.

Step-2:Read all the necessary input the keyboard.

Step-3:Pages-Logical memory is broke into fixed-sized blocks.

Step-4:Frames-Physical memory is broken into fixed-sized blocks.

Step-5:Calculate the physical address using the following physical address=(frame number *Frame
size)+offset.

Step-6:Display the physical address.

Step-7:Stop the program.


CODING:

#include<stdio.h>

#include<conio.h>

Void main()

Intnp,ns,i;

Int *sa;

Clrscr();

Printf(“enter how many pages:\n”);

Scanf(“%d”,&np);

Printf(“\nenter the page size:”);

Scanf(“%d”,&ps);

Sa=(int*)malloc(2*np);

For(i=0;i<np;i++)

Sa[i]=(int)malloc(ps);

Printf(“\npage%d\t address%u “,i+1,sa[i]);

Getch();

}
OUTPUT:

Enter how many pages:5

Enter the page size:4

Page1 Address:1894

Page2 Address:1902

Page3 Address:1910

Page4 Address:1918

Page5 Address:1926

RESULT:

Thus the Program was Executed and Output Verified Successfully.


Ex.no:12 THREAD AND SYNCHRONIZATION APPLICATION

Date:

AIM:

To write a c program to implement the thread and synchronization

ALGORITHM:

Step-1:Start the program

Step-2:Initialize the process thread array

Step-3:print the started status

Step-4:print the job finished status

Step-5:Start the main function

Step-6:Check for the process creation if not print error message

Step-7:Stop the program


CODING:

#include<stdio.h>

#include<string.h>

#include<pthread.h>

#include<stdlib.h>

#include<unistd.h>pt

hread_t tid[2];

int counter;

void*do something(void*arg)

Unsigned longi=0;

counter+=1;

printf("\njob%dstarted\n",counter);

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

printf("\njob%dfinished\n",counter);

return NULL;

intmain(void)

inti=0;

int err;

while(i<2)

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

if(err!=0)

printf("\ncannot create thread:[%s]",str error(err));

i++;

pthread_join(tid[0],NULL);

pthread_join(tid[1],NULL);
return0;

OUTPUT:

job1 started

job2 started

job2 finished

job2finished
RESULT:

Thus the Program was Executed and Output Verified Successfully.

You might also like