-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfork.c
55 lines (54 loc) · 1 KB
/
fork.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
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
//Geometric Series Function
int geomet(int lower, int constant, int upper)
{
if(upper>=lower)
{
int i;
for( i =0; i < upper; i++)
{
int sum =0;
sum = sum + lower;
lower = lower * constant;
printf("%d ",sum);
}
}
else
{
printf("Your upper bound cannot be less than the lower bound.\n");
}
}
int main()
{
pid_t pid;
pid = fork();
//Checking to see if busy
if (pid < 0) {
printf("Child Creation Failed\n");
exit(0);
}
//If not then proceed to execute function
else if (pid == 0)
{
int de,i,a,b,c /*a =2, b = 3, c = 6*/;
printf("Input lower bound\n");
scanf ("%d", &a);
printf("Input constant\n");
scanf ("%d", &b);
printf("Input upper bound\n");
scanf ("%d", &c);
de = geomet(a,b,c);
}
// parent process
else {
wait(NULL);
// waiting for child process to end
printf("Done\n");
}
exit(0);
}