// // Written for Computer Networks and Systems lab classes // AUTHOR : Sergiusz Warga #include #include #include #include #include #include int child_task(int a, int b) { return a + b; } int main() { srandom(time(NULL)); int a = random() % 11; int b = random() % 11 + 20; int sum = 0; pid_t pid; pid = fork(); if (pid == -1) { // If something went wrong. perror("Fork: "); exit(EXIT_FAILURE); } if (pid == 0) { // If this is a child process. sum = child_task(a, b); exit(sum); } wait(&sum); while (!(WIFEXITED(sum))); printf("%d\n", WEXITSTATUS(sum)); return 0; }