I have the following code and am asked to how many times "A", "B", "C", "D", "E" will be printed
fun() {
printf("A");
fork();
printf("B");
if (fork() != 0) {
printf("C");
fork();
printf("D");
}
printf("E");
}
so it should be:
A
A
B
E
im not sure if my answer above is correct? and what the line if(fork() !=0 ) do?
From the documentation:
On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With