Assignment 1 - Solutions
Assignment 1 - Solutions
Assignment 1 - Solutions
Q1)
Q2)
int main() {
pid_t pid1, pid2;
int x = 5;
int y = 3;
pid1 = fork();
if (pid1 == 0) {
writeToFile("factorial.txt",factorial(x));
exit(0);
}
pid2 = fork();
if (pid2 == 0) {
writeToFile("power.txt",power(y));
exit(0);
}
waitpid(pid1, NULL, 0);
waitpid(pid2, NULL, 0);
double fact_value, power_value;
fact_value = readFromFile("factorial.txt");
power_value = readFromFile("power.txt",);
double result = fact_value / power_value;
printf("Result: %lf\n",result);
return 0;
}