#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
int fibonacci(int n);
int main() {
int n;
printf("Enter the number of terms for Fibonacci series: ");
scanf("%d", &n);
pid_t pid = fork();
if (pid == -1) {
fprintf(stderr, "Fork failed\n");
return 1;
} else if (pid == 0) {
// Child process
printf("Child process is calculating Fibonacci series.\n");
for (int i = 0; i < n; ++i) {
printf("%d ", fibonacci(i));
}
printf("\n");
} else {
// Parent process
wait(NULL);
printf("Parent process is waiting for the child process to complete.\n");
}
return 0;
}
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}