I have the following function where I try to get an input from a user through the child process then get a random number from the parent process. After getting the random number from the parent process I would like to get another input from the child process. I tried using wait but the program just terminates anyway, is there any other way for me to go about this?
int main() {
int val, status;
int pid = fork();
if (pid > 0) {
srand(time(NULL));
int randNo = rand() % (100+ 1 - 0) + 0;
sleep(5);
printf("%d\n", randNo);
} else if (pid == 0) {
printf("Enter a value between 0 and 100: ");
scanf("%d", &val);
} else{
perror("fork");
exit(1);
}
}