Stack Overflow Asked by Mhennaoui Mohamed on December 18, 2021
tomorrow is my exam and i have difficulty in understanding fork() diagrams, all what i want is to correct me
fork()&&fork()&&fork()
i used this diagram
but my teacher told me that this is wrong and if u draw me this tomorrow i will give u negative marks, and he me told that this is the right one.
fork()&&fork()&&fork()
is equivalent to this:
if(fork()) {
if(fork()) {
fork();
}
}
From the documentation for fork()
you can read that it returns the pid of the child in the parent process, and 0 in the child process. So the second diagram is correct. No child process will invoke fork.
Answered by klutt on December 18, 2021
The fork()
returns the pid of the child in parent address space, some non-negative value. While in the child address space, a 0 is returned.
The &&
operand doesn't evaluate the rhs if the lhs is false, which is the case in the child process.
After first fork
Parent
true && fork() && fork()
Child
---> never evaluated
false && fork() && fork()
Answered by Tony Tannous on December 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP