THIRUVALLUVAR UNIVERSITY
INDO-AMERICANCOLLEGE
CHEYYAR- 604 407
DEPARTMENT OF COMPUTER APPLICATIONS
OPERATING SYSTEM LAB
2022 - 2023
Reg.No: ________________________________________
Name : __________________________________________
Class : __________________________________________
Subject: ___________________________________________
Subject Code: ________________________________________
THIRUVALLUVAR UNIVERSITY
INDO-AMERICANCOLLEGE
CHEYYAR-604 407
DEPARTMENT OF COMPUTER APPLICATIONS
Certified to be the bonafide record of practical work done by
______________________
With register number______________________in this department during the
Academic year
2022-2023.
Staff–in-charge Head of the department
Submitted for BCA degree practical examination held on ________________
Indo-American college, Cheyyar -604 407.
Examiners
,
Place: 1.
Date: 2.
INDEX
S.No DATE CONTENTS Page No Signature
1 BASIC UNIX COMMANDS
2 SHELL PROGRAMMING
3 CPU SCHEDLING ALGORITHM
a)ROUND ROBIN b)SJF c)FCFS d)PRIORITY
FILE ALLOCATION STRATEGIES
4
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
12 THREADING A
SYNCHORNIZATION
APPLICATIONS
Ex. No: 1
BASIC UNIX COMMANDS
Date:
AIM:
To write a basic commands in Linux
CODING:
1) date
Output: Saturday 01 October 2022 10:09:59 AM IST
2) cal
Output : October 2022
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 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 up to 1, 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 - gt 1]
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:Declare the variable
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>
void main()
{
int i,n,pid[15],bst[15],wait=0,tarnd,ts;
printf("\n Enter the no of process:");
scanf("%d",&n);
printf("\n Enter the values:");
for(i=1;i<=n;i++)
{
printf("\n Enter 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("\n pid\t burst\t wait\t tarnd");
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:
Enter the no of process:3
Enter the values:
Enter the process id: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:Declare the variable
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>
void 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("\n pid\t burst\t wait\t tarnd");
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:Declare the variable
Step-3:Get the required values using a for loop
Step-4:Print the turnaround time using a addition
Step-5:Stop the program
CODING:
#include<stdio.h>
void main()
{
int i,n,pid[5],bst[5],wait=0,tarnd;
printf("\n Enter 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\t burst\t wait\t tarnd");
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 id:5
Enter the process id:1
Enter the burst time:5
Enter the process id:2
Enter the burst time:5
Enter the process id:3
Enter the burst time:5
Enter the process id:4
Enter the burst time:5
Enter the process id:5
Enter the burst 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)
PRIORITY SCHEDULING
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>
void main()
{
int bt[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("\n p[%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("\n process \t burst time \t waiting time \t turn around time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\n p[%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("\n Average turn around 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 turn around 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 turn around 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 sequantial order
a)randomaly select a locatin from available location S1=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 fileno,length,blocks allocated
Step-6:Stop the program
CODING:
#include<stdio.h>
#include<stdlib.h>
void main()
int f[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("\n the 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;
else
exit;
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 memeory requirement of each file
Step-4:Allocate the required location by selecting a location randomly
Step-5:Print the results file number length ,blocks allocated
Step-6:Stop the program
CODING:
#include<stdio.h>
void main()
{
int f[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 0 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:1enter 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 a location randomly
Step-4:Check whether the selected location free
Step-5:If the location is free allocated and set flag=1 to the allocated location
Step-6:Print the result fileno,length,blocks allocated
Step-7:Stop the program
CODING:
#include<stdio.h>
void main()
{
int f[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 are already 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 alloacted",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:
Enter how many blocks that are already allocated:3
Enter the blocks no.s print are already allocated:6
8
10
Enter the starting index block&length:3 10
3->1
4->1
5->1
6-> file is already alloacted
7->1
8-> file is already alloacted
9->1
10-> file is already alloacted
11->1
12->1
13->1
14->1
15->1
If you want to enter one more 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>
void main()
{
int n,a[5],in,out,pr,cr,ch;
in=out=pr=cr=0;
printf("\nEnter 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;
case 2:
if(in==out)
printf("\n The buffer is underflowing:");
else if(pr==1)
printf("\n The Producer process is going on:");
else
{
cr=1;
printf("\n The element %d is consumer:",a[in]);
in--;
if(in==0)
cr=0;
}
break;
}
}
while(ch!=3);
}
OUTPUT:
Enter the no of element: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
Enter the element:40
1.proceducer
2.customer
3.exit:
Enter the choice:1
Enter the element:56
1.proceducer
2.customer
3.exit:
Enter the choice:1
The Buffer is overflowing
1.proceducer
2.customer
3.exit:
Enter the choice:2
The element 56 is consumer:
1.proceducer
2.customer
3.exit:
Enter the choice:2
The element 40 is consumer:
1.proceducer
2.customer
3.exit:
Enter the choice:2
The element 20 is consumer:
1.proceducer
2.customer
3.exit:
Enter the choice:2
The buffer is underflowing
1.proceducer
2.customer
3.exit:
Enter the choice: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:
Step 1: Start the Program
Step 2: Initialize values gd=DETECT,gm,count,i,j,mid,cir_x.
Step 3: Initialize graph function
Step 4: Set back ground color with setbkcolor();
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
char dname[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\n 1. Create File\t2. Delete File\t3. Search File \n 4. Display Files\t5. Exit\nEnter your choice -- ");
scanf("%d",&ch);
switch(ch)
case 1: printf("\n Enter the name of the file -- ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2: printf("\n Enter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f, dir.fname[i])==0)
printf("File %s is deleted ",f);
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
if(i==dir.fcnt)
printf("File %s not found",f);
else
dir.fcnt--;
break;
case 3: printf("\n Enter the name of the file -- ");
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f, dir.fname[i])==0)
printf("File %s is found ", f);
break;
if(i==dir.fcnt)
printf("File %s not found",f);
break;
case 4: if(dir.fcnt==0)
printf("\n Directory Empty");
else
{
printf("\n The Files are -- ");
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
break;
default: exit(0);
getch();
OUTPUT:
Enter name of directory -- CSE
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 1
Enter the name of the file -- A
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 1
Enter the name of the file -- B
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 1
Enter the name of the file -- C
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 4
The Files are -- A B C
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 3
Enter the name of the file – ABC
File ABC not found
1. Create File 2. Delete File 3. Search File
4. Display Files 5. Exit Enter your choice – 2
Enter the name of the file – B
File B is deleted
1. Create File 2. Delete File 3. Search File
4. Display Files 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: Set variables gd =DETECT, gm;
Step-5: Create structure using create (&root,0,”null”,0,639,320);
Step-6: initgraph(&gd,&gm,”c:\tc\bgi”);
Step-7: Stop the program
CODING:
#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)
printf("\n\n 1. Create Directory\t 2. Create File\t 3. Delete File");
printf("\n 4. Search File \t \t 5. Display \t 6. Exit \t Enter your choice -- ");
scanf("%d",&ch);
switch(ch)
case 1: printf("\n Enter name of directory -- ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
case 2: printf("\n Enter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
printf("Enter name of the file -- ");
scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;
printf("File created");
break;
if(i==dcnt)
printf("Directory %s not found",d);
break;
case 3: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
printf("Enter name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
printf("File %s is deleted ",f);
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
}
printf("File %s not found",f);
goto jmp;
printf("Directory %s not found",d);
jmp : break;
case 4: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
printf("Enter the name of the file -- ");
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
printf("File %s is found ",f);
goto jmp1;
printf("File %s not found",f);
goto jmp1;
printf("Directory %s not found",d);
jmp1: break;
case 5: if(dcnt==0)
printf("\nNo Directory's ");
else
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
break;
default:exit(0);
getch();
OUTPUT:
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Enter name of directory -- DIR1
Directory created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 1
Enter name of directory -- DIR2
Directory created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory – DIR1
Enter name of the file -- A1
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory – DIR1
Enter name of the file -- A2
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 2
Enter name of the directory – DIR2
Enter name of the file -- B1
File created
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 5
Directory Files
DIR1 A1 A2
DIR2 B1
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 4
Enter name of the directory – DIR
Directory not found
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter your choice -- 3
Enter name of the directory – DIR1
Enter name of the file -- A2
File A2 is deleted
1. Create Directory 2. Create File 3. Delete File
4. Search File 5. Display 6. Exit Enter 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:
Step 1: Start the Program
Step 2: Define structure and declare structure variables
Step 3: start main and declare variables
Step 4: Check a directory tree structure
Step 5: Display the directory tree in graphical mood
Step 6: Stop the program
CODING:
#include<stdio.h>
#include<graphics.h>
struct tree_element
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element
node; void main()
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();
create(node **root,int lev,char *dname,int lx,int rx,int x)
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 forfile :");
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("No of sub directories/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;
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):USER 1
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER 1):1
Enter Name of dir/file (under USER 1):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 subdirectories /files (for VB): 0
Enter Name of dir/file (under ROOT):USER2
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER2):2
Enter Name of dir/file (under ROOT):A
Enter 1 for Dir /2 for file:2
Enter Name of dir/file (under USER2):SUBDIR 2
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for SUBDIR 2):2
Enter Name of dir/file (under SUBDIR2):PPL
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for PPL):2
Enter Name of dir/file (under PPL):B
Enter 1 for Dir /2 for 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 graph along with name using graphics
Step-8: Stop the program
CODING:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
struct tree_element
char name[20];
int x,y,ftype,lx,rx,nc,level;
struct tree_element *link[5];
};
typedef struct tree_element
node; typedef struct
char from[20];
char to[20];
}link; link
L[10]; int
nofl;
node * root;
void main()
int gd=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()
int i;
printf("how many links");
scanf("%d",&nofl);
for(i=0;i<nofl;i++)
printf("File/dir:");
fflush(stdin);
gets(L[i].from);
printf("user name:");
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);
setlinestyle(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,int lev,char *dname,int lx,int rx,int x)
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("no of sub directories /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): USER 1
Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER 1): 2
Enter Name of dir/file (under USER1): 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 (under USER1): 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 (under USER2):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 subdirectories /files (for HTML):0
How many links:2
File/Dir: B
User Name: USER 2
File/Dir: HTML
User Name: 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 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>
int max[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]);
}
}
}
void call()
{
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("\nProcess are in dead lock");
printf("\n The System is in unsafe state");
}
}
OUTPUT:
DEADLOCK AVOIDANCE
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 0 2
2 2 1
Enter the allocation matrix:
101
111
Enter the available resources:
111
Process Allocation Maximum Available
P0 : 1 0 1 1 0 2 1 1 1
P1 : 1 1 1 3 2 1
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>
int max[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 Detection");
input();
show();
call();
getch();
}
void input()
{
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]);
}
}
}
void call()
{
int finish[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("\n system is in deadlock and the dealdock process are \n");
for(i=0;i<n;i++)
{
printf("P%d :",dead[i]);
}
}
else
printf("\n no deadlock occur");
}
OUTPUT:
DEADLOCK DETECTION
Enter no of processes:
2
Enter no of resource instances:
3
Enter the max matrix:
1 1 1
2 1 2
Enter the allocation matrix:
100
201
Enter the available resources:
000
Process Allocation Maximum Available
P0 : 1 0 0 1 1 1 0 0 0
P1 : 2 0 1 2 1 2
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 array a[i].
Step-5:Initialize aval[i]=0 to check page hit.
Step-6:print the results.
Step-7:Stop the program.
CODING:
#include<stdio.h>
void main()
int a[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("\n No of faults:%d",m);
OUTPUT:
Enter the number of pages:10
Enter the 10 page numbers:1 2 3 4 5 1 2 3 4 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 of faults: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 satck
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()
int g=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("\n no.fault:%d",m);
OUTPUT:
Enter the number of pages:12
Enter 12 page number:2 3 2 1 5 2 4 5 3 2 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 Repalce The Page With The Page That Is Leastly Used
Step-7:Print Page Number Of Page Faults
Step-8:Stop the program
CODING:
#include<stdio.h>
void main()
int rs[50],i,j,k,m,f,cntr[20],a[20],min,pf=0;
printf("Enter no.of page reference--");
scanf("%d",&m);
printf("\n Enter the reference string--");
for(i=0;i<m;i++)
scanf("%d",&rs[i]);
printf("\n Enter the available no of frames--");
scanf("%d",&f);
for(i=0;i<f;i++)
cntr[i]=0;
a[i]=-1;
printf("\n Enter 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("\t PF no %d",pf);
printf("\n Total no of page faults:%d",pf);
OUTPUT:
Enter no.of page reference--12
Enter the reference string--1 2 3 4 5 2 5 2 5 1 4 3
Enter the available no of frames--3
Enter 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 PF no 5
5 2 3 PF no 5
5 2 3 PF no 5
5 2 3 PF no 5
5 2 1 PF no 6
5 2 4 PF no 7
5 2 3 PF no 8
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>
void 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 PAGING TECHNIQUE OF MEMORY MANAGEMENT
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()
Int np,ns,i;
Int *sa;
Clrscr();
Printf(“enter how many pages:\n”);
Scanf(“%d”,&np);
Printf(“\n enter the page size:”);
Scanf(“%d”,&ps);
Sa=(int*)malloc(2*np);
For(i=0;i<np;i++)
Sa[i]=(int)malloc(ps);
Printf(“\n page%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>
pthread_t tid[2];
int counter;
void*dosomething(void*arg)
unsigned long i=0;
counter+=1;
printf("\n job%d started\n",counter);
for(i=0;i<(0xFFFFFFFF);i++);
printf("\n job%d finished\n",counter);
return NULL;
int main(void)
int i=0;
int err;
while(i<2)
err=pthread_create(&(tid[i]) ,NULL,&dosomething,NULL);
if(err!=0)
printf("\n cannot create thread:[%s]",strerror(err));
i++;
pthread_join(tid[0],NULL);
pthread_join(tid[1],NULL);
return 0;
OUTPUT:
job1 started
job2 started
job2 finished
job2 finished
RESULT:
Thus the Program was Executed and Output Verified Successfully.