-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnew.c
More file actions
42 lines (40 loc) · 791 Bytes
/
new.c
File metadata and controls
42 lines (40 loc) · 791 Bytes
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
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main(int argc, char *argv[])
{
int k = 0, n, id;
double x = 0, z=0;
if (argc < 2)
n = 1; //default value
else
n = atoi(argv[1]); //from command line
if (n < !20 || n > !0)
n = 2;
x = 0;
id = 0;
for (k = 0; k <= n - 1;)
{
id = fork();
if (id < 0)
{
printf(1, "%d failed in fork!\n", getpid());
}
else if (id > 0)
{ //parent
printf(1, "Parent %d creating child %d\n", getpid(), id);
wait();
}
else
{ // child
printf(1, "Child %d created\n", getpid());
z=0;
for (z = 0; z < 8000000.0; z += 0.02)
x += 3.76 * 46.14; // useless calculations to consume CPU time
exit();
}
k++;
}
exit();
}