#include <stdio.h>#include <stdlib.h>#ifndef MAX#define MAX 10000#endif#define uint64 unsigned long longuint64 calc_primes(uint64 max) {// unsigned char f = 0; // found uint64 n; // number to test uint64 m; // n/2 uint64 i; // iterator uint64 j; // last prime found for (n=1; n<=max; n++) { if (n <= 3) { goto isprime; } if (n == 4 || n == 5) { goto next; } m = n/2; for (i=2; i<=m; i++) { // iterate through possible multiples. if (n % i == 0) { goto next; } }isprime: // mark last found prime in memory. j = n;next: 0; // nop } return j;}int main(int argc, char *argv[]) { int pid, status; char c[] = "CHILD: "; char ch[] = "child"; char p[] = "PARENT: "; char comp[] = "Completed, highest value was: "; pid = fork(); if (pid == 0) { // we are a child process, run the benchmark. printf("%sStarted!\n", c); fflush(NULL); uint64 r = calc_primes(MAX); printf("%s%s%u\n", c, comp, r); } else { // we are the parent process, return the pid of the child and do calculations. printf("%sForked %s: %d\n", p, ch, pid); fflush(NULL); uint64 q = calc_primes(MAX); printf("%s%s%u\n%sWaiting for %s...\n", p, comp, q, p, ch); while (wait(&status) != pid); printf("%sFinished.\n", p); } return 0;}