-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest2.c
69 lines (65 loc) · 1.11 KB
/
test2.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
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <string.h>
#include <errno.h>
unsigned long long nCr(unsigned long long n, unsigned long long r)
{
if(n>=r)
{
if(r==0 || r==n)
{
return 1;
}
else
{
return nCr(n-1,r-1) + nCr(n-1,r);
}
}
else
{
return 0;
}
}
int main()
{
long int pid=fork();
if(pid!=0)
{
long ret = syscall(323,pid,300);
printf("%s\n",strerror(ret));
}
if(pid==0)
{
int pid2=fork();
if(pid2 != 0)
{
long ret2 = syscall(323,pid2,200);
printf("%s\n",strerror(ret2));
}
if(pid2==0)
{
unsigned long long ans = nCr(30,15);
printf("Finished calculating 30C15\n");
printf("Process with PID %ld finished\n",getpid());
}
else
{
unsigned long long ans = nCr(30,15);
printf("Finished calculating 30C15\n");
printf("Process with PID %ld finished\n",getpid());
wait(pid2);
}
}
else
{
unsigned long long ans = nCr(30,15);
printf("Finished calculating 30C15\n");
printf("Process with PID %ld finished\n",getpid());
wait(pid);
}
return 0;
}