-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuestion2.c
More file actions
43 lines (43 loc) · 1.03 KB
/
Copy pathQuestion2.c
File metadata and controls
43 lines (43 loc) · 1.03 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
//Write a program to create a child presses
//the parents print "integer no." and child prints "Integer number" user defind .
// Also both the message prints the same common message.
#include<stdio.h>
#include<dirent.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
pid_t p;
int i, j,Pn,Pm,Cn,Cm;
printf("Enter the start value of Child: \n");
scanf("%d", &Cn);
printf("Enter the end value of Child:\n");
scanf("%d", &Cm);
printf("Enter the start value of Parents:\n");
scanf("%d", &Pn);
printf("Enter the end value of Parents:\n");
scanf("%d", &Pm);
p = fork(); //a duplicate or child process creater
switch (p)
{
case 1:
printf("Error");
break;
case 0://child execution
for(i=Cn;i<Cm;i++)
{
printf("%d\n",i);
}
break;
default:// wait() //Parent is executing
for(j=Pn;j<Pm;j++)
{
printf("%d\n",j);
sleep(1);
}
}
printf("\ncommon message.!.\n");
}