-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq1.c
60 lines (48 loc) · 1.05 KB
/
q1.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#define MAX_COUNT 20
void childProcess(void);
void parentProcess(void);
int main(int argc, char **argv)
{
pid_t pid;
pid = fork();
if (pid < 0)
{
printf("error unable to fork process; ending program");
}
if (pid == 0)
{
childProcess();
}
else
{
printf("the fork command returns PID of the child: %d\n",pid );
parentProcess();
}
}
void childProcess()
{
int i, x , pid1, pid2;
pid1 = getpid();
for (i = 0; i <= MAX_COUNT; i++)
{
printf("this line is from child (pid number %d) the pid of the parent is %d, value = %d\n", pid1,pid2,i );
for ( x = 0; x < 10000000000; x++)
{
printf("child process is done\n");
}
}
}
void parentProcess()
{
int i, x, pid1;
pid1 = getpid();
for (i = 1; i < MAX_COUNT; i++)
{
printf("this line is from parent (pid number %d), value = %d\n", pid1,i );
for ( x = 0; x < 10000000000; x++);
}
printf("Parent is done\n");
}