I have been tasked with writing a C program which allows the child code to finish after the parent, using the sleep command.
This is what I have written, the code does not work and it only returns the 'else' part of the code. If anyone could help it would be much appreciated. I believe the problem is how I have used the sleep command.
#include <stdio.h>
#include <unistd.h>
int main() {
fork();
if (fork() ==0){
sleep(5);
printf("This will finish after the parent\n");
}
else
printf("This will finish before the child\n");
return 0;
}