summaryrefslogtreecommitdiffstats
path: root/tests/manual/clients/fork.c
blob: c17f80a177d43eeccc305fb34cf0d26dfc519064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// SPDX-License-Identifier: LGPL-2.1-or-later

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <math.h>

int main()
{
    pid_t child = fork();
    if (child == 0) {
        double sum = 0;
        for (int i = 0; i < 1000000; ++i) {
            sum += cos(cos(i) * cos(i) + cos(i * i) + cos(cos(i)));
        }
        printf("sum is: %g\n", sum);
    } else {
        printf("waiting for child\n");
        waitpid(child, NULL, 0);
        printf("done waiting\n");
    }
    return 0;
}