-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdpro.c
37 lines (33 loc) · 798 Bytes
/
dpro.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
#include "types.h"
#include "stat.h"
#include "user.h"
int main(int argc, char *argv[]) {
int n;
int x, z;
if(argc < 2)
n = 1; //Default
else
n = atoi(argv[1]);
if (n < 0 || n > 20)
n = 2;
x = 0;
int pid = 0;
for (int k = 0; k < n; k++)
{
pid = fork();
if ( pid < 0 ) {
printf(1, "%d failed in fork!\n", getpid());
} else if (pid > 0) {
// parent
printf(1, "Parent %d creating child %d\n",getpid(), pid);
wait();
}
else{
printf(1, "Child %d created\n",getpid());
for(z = 0; z < 4000000000; z+=1)
x = x + 3.14*89.64; //Useless calculation to consume CPU Time
break;
}
}
exit();
}