3.operating Systems Lab 1
3.operating Systems Lab 1
com
Prepared by
Ms.K.Subha Assistant Professor
Faculty of Computer Science & Engineering
pid=fork();
if(pid<0)
{
printf("fork failed");
exit(1);
}
else if(pid==0)
{
execlp("whoami","ls",NULL);
exit(0);
}
else
{
printf("\n Process id is -%d\n",getpid());
wait(NULL);
exit(0);
}
}
OUTPUT:
[cse6@localhost Pgm]$ cc prog4a.c
[cse6@localhost Pgm]$ ./a.out
RESULT:
Thus the program was executed and verified successfully
RESULT:
Thus the program was executed and verified successfully
10
int fd1,fd2,n;
char source[30],ch[5];
struct stat s,t,w;
fd1=creat("text.txt",0644);
printf("Enter the file to be copied\n");
scanf("%s",source);
fd2=open(source,0);
if(fd2==-1)
{
perror("file doesnot exist");
exit(0);
}
while((n=read(fd2,ch,1))>0)
write(fd1,ch,n);
close(fd2);
stat(source,&s);
printf("Source file size=%d\n",s.st_size);
fstat(fd1,&t);
printf("Destination file size =%d\n",t.st_size);
close(fd1);
}
RESULT:
Thus the program was executed successfully.
12
EX.NO : 1)viii PROGRAM USING SYSTEM CALLS open( ), read() & write( )
AIM : To write the program to implement the system calls open( ),read( ) and write( ).
ALGORITHM :
Step 1 : Declare the structure elements.
Step 2 : Create a temporary file named temp1.
Step 3 : Open the file named test in a write mode.
Step 4 : Enter the strings for the file.
Step 5 : Write those strings in the file named test.
Step 6 : Create a temporary file named temp2.
Step 7 : Open the file named test in a read mode.
Step 8 : Read those strings present in the file test and save it in temp2.
Step 9 : Print the strings which are read.
SYSTEM CALLS USED :
1.
open( )
2.
read( )
3.
write( )
close( )
4.
5.
gets( )
6.
lseek( )
PROGRAM CODING:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<fcntl.h>
main( )
{
int fd[2];
char buf1[25]= just a test\n; char
buf2[50];
fd[0]=open(file1, O_RDWR);
fd[1]=open(file2, O_RDWR);
write(fd[0], buf1, strlen(buf1));
printf(\n Enter the text now.);
gets(buf1);
write(fd[0], buf1, strlen(buf1));
lseek(fd[0], SEEK_SET, 0);
read(fd[0], buf2, sizeof(buf1));
write(fd[1], buf2, sizeof(buf2));
close(fd[0]);
close(fd[1]);
printf(\n);
return0;
}
13
OUTPUT:
Enter the text now.progress
Cat file1 Just a
test progress
Cat file2 Just a test progress
RESULT:
Thus the program was executed successfully
14
15
17
18
19
20
21
22
23
{
wt[i]=tt[i]=0;
printf("P%d\t: ",i+1);
scanf("%d",&b[i]);
rem[i]=b[i];
tbt+=b[i];
flag[i]=0;
}
from=0;
i=0;
printf("\n\t Gantt Chart");
printf("\n ProcessID\tFrom Time\tTo Time\n");
while(from<tbt)
{
if(!flag[i])
{
if(rem[i]<=ts)
{
dur=rem[i];
flag[i]=1;
tt[i]=dur+from;
wt[i]=tt[i]-b[i];
}
else
dur=ts;
printf("%7d%15d%15d\n",i+1, from,from+dur);
rem[i] -= dur;
from += dur;
}
i=(i+1)%nop;
}
for(i=0;i<nop;i++)
{
twt+=wt[i];
ttt+=tt[i];
}
printf("\n\n Process ID \t Waiting Time \t Turn Around Time");
for(i=0;i<nop;i++)
{
printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);
}
awt=(float)twt/(float)nop;
att=(float)ttt/(float)nop;
printf("\nTotal Waiting Time:%d",twt);
printf("\nTotal Turn Around Time:%d",ttt);
printf("\nAverage Waiting Time:%.2f",awt);
printf("\nAverage Turn Around Time:%.2f\n",att);
}
OUTPUT:
25
ProcessID
1
2
3
1
2
1
1
1
1
1
1
Gantt Chart
From Time
0
3
6
9
12
14
17
20
23
26
29
To Time
3
6
9
12
14
17
20
23
26
29
32
Process ID
Waiting Time
1
8
2
9
3
6
Total Waiting Time:23
Total Turn Around Time:55
Average Waiting Time:7.67
Average Turn Around Time:18.33
RESULT:
Thus the program was executed successfully
26
ALGORITHM:
Step 1: Get the number of process.
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time of
first short is process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.
Step 5: Waiting time of one process is the total time of the previous process.
Step 6: Total time of process is calculated by adding the waiting time and
service
time of each process.
Step 7: Total waiting time calculated by adding the waiting time of each process.
Step 8: Total turn around time calculated by adding all total time of each
process. Step 9: Calculate average waiting time by dividing the total waiting
time by total
number of process.
Step 10: Calculate average turn around time by dividing the total waiting time
by total number of process.
Step 11: Display the result.
PROGRAM CODING:
#include<stdio.h> int main()
{
int n,w[100],tot[100],i,j,awt,atot; float avwt,avtot;
struct
{
int p,bt; }sjf[10],temp;
printf("Enter the number of Processes:"); scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the Burst time for Process%d : ",i); scanf("%d",&sjf[i].bt);
sjf[i].p=i;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(sjf[j].bt>sjf[i].bt)
{
27
temp=sjf[i];
sjf[i]=sjf[j];
sjf[j]=temp;
}
w[1]=0;
tot[1]=sjf[1].bt;
for(i=2;i<=n;i++) tot[i]=tot[i-1]+sjf[i].bt;
awt=0;
atot=0;
for(i=1;i<=n;i++)
{
w[i]=tot[i]-sjf[i].bt; awt+=w[i]; atot+=tot[i];
}
avwt=(float)awt/n;
avtot=(float)atot/n;
printf("\n\nProcessId\tWaiting time\t TurnaroundTime");
for(i=1;i<=n;i++)
printf("\n\t%d\t\t%d\t\t%d",sjf[i].p,w[i],tot[i]);
printf("\n\nTotal Waiting Time :%d",awt);
printf("\n\nTotal Turnaround Time :%d",atot);
printf("\n\nAverage Waiting Time :%.2f",avwt);
printf("\n\nAverage Turnaround Time :%.2f",avtot); }
OUTPUT:
[cse6@localhost Pgm]$ cc prog9b.c
[cse6@localhost Pgm]$ ./a.out
Enter the number of Processes:3
Enter the Burst time for Process1 : 24
Enter the Burst time for Process2 : 5
Enter the Burst time for Process3 : 3
ProcessId
Waiting time
3
0
2
3
1
8
Total Waiting Time :11
Total Turnaround Time :43
Average Waiting Time :3.67
Average Turnaround Time :14.33
[cse6@localhost Pgm]$
TurnaroundTime
3
8
32
RESULT:
Thus the program is executed.
28
{
t=t+w;
r=r+b[i];
printf("P%d\t\t%d\t\t%d\t\t%d\t\t\n",i,b[i],w,r);
w=w+b[i];
a=a+r;
}
avg=(float)t/n;
avg1=(float)a/n;
printf("\n Average WaitingTime is %f",avg); printf("\n
Average TurnaroundTime is %f\n",avg1); return(0);}
OUTPUT:
[cse6@localhost Pgm]$ cc prog9a.c -o prog9a.out
[cse6@localhost Pgm]$ ./prog9a.out
Enter number of processes : 3
Enter the burst times :
24
5
3
Gantt chart
Process
P1
P2
P3
P1
P2
P3
30
32
34
OUTPUT:
[cse6@localhost Pgm]$ cc prog10a.c
[cse6@localhost Pgm]$ ./a.out
Enter the no. of processes : 3 Enter the
burst times
P1 : 24
P2 : 5
P3 : 3
Enter the priorities
P1 : 2
P2 : 1
P3 : 3
Gantt Chart : P2
P1P3
P1
24
29
P3
29
32
35
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:Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM CODING:
#include<stdio.h>
void main()
{
char a[10];
int i,ib,cib[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n index block:");
scanf("%d",&ib);
for(i=1;i<=5;i++)
{
printf("\n enter the child of index block %d:",i);
scanf("%d",&cib[i]);
}
printf("\n the list of files\t index block\n");
printf("%s\t\t %d",a,ib);
printf("\n the above file utiltization index block of child blocks followin\t");
printf("\n");
for(i=1;i<=5;i++)
{
printf("%d\t\t",cib[i]);
}
printf("\n");
}
RESULT:
Thus the program was executed successfully.
36
OUTPUT:
Enter the name:Testing
Index block:19
Enter the child of index block 1:9
Enter the child of index block 2:16
Enter the child of index block 3:1
Enter the child of index block 4:10
Enter the child of index block 5:25
The list of files
Testing
index block
19
16
10
25
37
ALGORITHM:
Step 1: Start the Program
Step 2:Obtain the required data through char and int datatypes.
Step 3:Enter the filename,starting block ending block.
Step 4: Print the free block using loop.
Step 5:for loop is created to print the file utilization of linked type of entered type .
Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution.
PROGRAM CODING
#include<stdio.h>
void main()
{
char a[10];
int i,sb,eb,fb1[10];
printf("\n enter the file name:");
scanf("%s",a);
printf("\n Enter the starting block:");
scanf("%d",&sb);
printf("Enter the ending Block:");
scanf("%d",&eb);
for(i=0;i<5;i++)
{
printf("Enter the free block %d",i+1);
scanf("%d",&fb1[i]);
}
printf("\n File name \t Starting block \t Ending block \n");
printf("%s \t\t %d\t\t %d",a,sb,eb);
printf("\n %s File Utilization of Linked type of following blocks:",a);
printf("\n %d->",sb);
for(i=0;i<5;i++)
{
printf("%d->",fb1[i]);
}
printf("%d\n",eb);
}
RESULT:
Thus the program was executed successfully.
38
OUTPUT:
Enter the
filename:binary Enter
the starting block:19
Enter the ending
block:25 Enter the free
block:1:12 Enter the free
block:2:34 Enter the free
block:3:21 Enter the free
block:4:18 Enter the free
block:5:35
File name
Binary
ending
block
25
starting block
19
39
break;
}
}
}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
x++;
printf("\n producer produces the items %d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes the item %d",x);
x--;
mutex=signal(mutex);
}
RESULT:
Thus the program was executed successfully
41
OUTPUT:
[cse6@localhost Pgm]$ cc ex11.c -o ex11.out
[cse6@localhost Pgm]$ ./ex11.out
Produced element a
Consumed element a
Produced element b
Consumed element b
Produced element c
Consumed element c
Produced element d
Consumed element d
Produced element e
Consumed element e
Produced element f
Consumed element f
Produced element g
Consumed element g
Produced element h
Consumed element h
42
for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,cir_x,250);
fillellipse(cir_x,250,30,30);
outtextxy(cir_x,250,fname[j]);
}
getch();
}
}
RESULT:
Thus the program was executed successfully.
44
if(lev==0||lev==1)
(*root)->ftype=1; else
(*root)->ftype=2;
(*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)
{
if(lev==0||lev==1)
{
if((*root)->level==0)
printf("How many users");
else
printf("hoe many files");
printf("(for%s):",(*root)->name);
scanf("%d",&(*root)->nc);
}
else (*root)->nc=0; 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,roo>y+10,0,0);
else
fillellipse(root->x,root->y,20,20);
outtextxy(root->x,root->y,root->name);
46
for(i=0;i<root->nc;i++)
{
display(root->link[i]);
}
}
}
RESULT:
Thus the program was executed successfully.
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 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;
}
}
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++)
48
{
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]); } } }
RESULT:
Thus the program was executed successfully.
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);
}
50
}
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;
51
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]);
}
}
}
RESULT:
Thus the program was executed successfully.
52
k=k+alloc[i][j];
}
avl[i]=avl[i]-k;
work[i]=avl[i];
}
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
{
count=0;
for(j=1;j<=m;j++)
{
if((finish[i]==f)&&(need[i][j]<=work[i])) of
count++;
}
if(count==m)
{
for(l=1;l<=m;l++)
work[l]=work[l]+alloc[i][l];
finish[i]=t;
pr[k]=i;
JBIET
break;
}
}
for(i=1;i<=n;i++)
if(finish[i]==t)
fcount++;
if(fcount==n)
{
printf(the system is in safe state);
Dept
for(i=1;i<=n;i++)
printf(%d,pr[i]);
}
else
printf(the system is not in safe state);
getch();
}
RESULT:
Thus the program was executed successfully.
54
{
sum=0;
for(j=1;j<=tr;j++)
{
sum+=p[i][j];
}
if(sum==0)
{
m[k]=i;
k++;
}
}
for(i=1;i<=tp;i++)
{
for(l=1;l<k;l++)
if(i!=m[l])
{
flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
{
flag=0;
break;
}
}
if(flag==1)
{
m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
}
}
printf("deadlock causing processes are:");
for(j=1;j<=tp;j++)
{
found=0;
for(i=1;i<k;i++)
{
if(j==m[i])
found=1;
}
if(found==0)
printf("%d\t",j);
}
getch();
}
OUTPUT:
56
RESULT:
Thus the program was executed successfully.
57
if(i!=0) frames[j][i]=frames[j][i-1];
//checking whether page is there in frames
or not if(frames[j][i]==pages[i])
found='t';
}
//if PAGE is not there in
frames if(found=='f')
{
faults++;
fillcount++;
if(fillcount<=no_f)
{
frames[pos][i]=pages[i];
pos++;
}
IT
else
{
for(j=0;j<no_f;j++)
ppos[j]=0;
for(j=0;j<no_f;j++)
{
for(k=i-3;k<i;k++)
{
if(frames[j][i]==pages[k])
ppos[j]=k;
}
}
least=ppos[0];
for(j=0;j<no_f;j++)
{
if(ppos[j]<least)
least=ppos[j];
}
for(j=0;j<no_f;j++)
if(pages[least]==frames[j][i])
pos=j;
frames[pos][i]=pages[i];
}
}
//printing frames each time we
enter a no settextstyle(2,0,6);
for(k=0;k<no_f;k++)
59
{
for(j=0;j<=i;j++)
{
rectangle(x1,y1,x1+40,y1+45);
if(frames[k][j]!=0)
{
//changing text color in case of replacement
if(j==i&&frames[k][j]==pages[i]&&found=='f')
setcolor(MAGENTA);
else
setcolor(WHITE);
itoa(frames[k][j],str,10);
outtextxy(x1+15,y1+15,str);
}
else
outtextxy(x1+10,y1+10,"");
setcolor(WHITE);
x1+=55;
}
y1+=45;
x1=20;
}
}
//printing page fault ratio
printf("/n/n page fault
ratio=%f",(float)faults/(float)no_p); getch();
}
RESULT:
Thus the program was executed successfully.
60
found='f';
for(j=0;j<no_f;j++)
{
if(i!=0) frames[j][i]=frames[j][i-1];
//checking whether page is there in frames
or not if(frames[j][i]==pages[i])
found='t';
}
//if PAGE is not there in
frames if(found=='f')
{
faults++;
fillcount++;
if(fillcount<=no_f)
frames[pos][i]=pages[i];
pos++;
}
else
{
for(j=0;j<no_f;j++)
ppos[j]=0;
for(j=0;j<no_f;j++)
{
for(k=0;k<i;k++)
{
if(frames[j][i]==pages[k])
Computer Networks & Operating Systems Lab Manual
ppos[j]++;
}
}
least=ppos[0];
for(j=0;j<no_f;j++)
{
if(least>ppos[j])
least=ppos[j];
}
ocurs='n';
for(j=0;j<1&&occur=='n';j++)
{
for(k=0;k<no_f;k++)
{
if(pages[j]==frames[k][i]&&ppos[k]==least)
62
{
pos=k;
occur='y';
}
}
}
frames[pos][i]=pages[i];
}
}
//printing frames each time we
enter a no settextstyle(2,0,6);
for(k=0;k<no_f;k++)
{
for(j=0;j<=i;j++)
{
rectangle(x1,y1,x1+40,y1+45);
if(frames[k][j]!=0)
{
//changing the text color when page is replaced of
if(j==i&&frames[k][j]==pages[i]&&found=='f')
setcolor(MAGENTA);
else
setcolor(WHITE);
itoa(frames[k][j],str,10);
outtextxy(x1+15,y1+15,str);
}
else
outtextxy(x1+10,y1+10,"");
setcolor(WHITE);
x1+=55;
}
y1+=45;
x1=20;
}
}
//printing page fault ration
printf("page fault ration
%f",(float)faults/(float)no+p); getch();
}
RESULT:
Thus the program was executed successfully
63
cleardevice();
x1=20,y1=100;
found='f';
for(j=0;j<no_f;j++)
{
if(i!=0) frames[j][i]=frames[j][i-1];
//checking whether page is there in frames or not
if(frames[j][i]==pages[i])
found='t';
}
//if PAGE is not there in
frames if(found=='f')
{
frames[pos][i]=pages[i];
faults++;
if(pos<no_f)
pos++;
else pos=0;
}
//printing frames each time we
enter a no settextstyle(2,0,6);
for(k=0;k<no_f;k++)
{
for(j=0;j<=i;j++)
{
rectangle(x1,y1,x1+40,y1+45);
if(frames[k][j]!=0)
{
//changing the text color when page is replaced
if(j==i&&frames[k][j]==pages[i]&&found=='f')
JBIET
setcolor(MAGENTA);
else
setcolor(WHITE);
itoa(frames[k][j],str,10);
outtextxy(x1+15,y1+15,str);
}
else
outtextxy(x1+10,y1+10,"");
setcolor(WHITE);
x1+=55;
}
65
y1+=45;
x1=20;
}
}
//printing page fault ratio
printf("page fault ration
%f",(float)faults/(float)no_p); getch();
}
RESULT:
Thus the program was executed successfully.
while(1)
{
sem.sem_num=0;
sem.sem_op=-1;
sem.sem_flg=0;
semop(semid,&sem,1);
*ptr=*ptr+1;
printf("process id:%d countis :%d \n",getpid(),*ptr);
for(j=1;j<=1000000;j++)
{
sem.sem_num=0;
sem.sem_op=+1;
sem.sem_flg=0;
semop(semid,&sem,1);
}
}
shmdt(ptr);
}
RESULT:
Thus the program was executed
67