What does fork() actually return?
HTML-код
- Опубликовано: 16 май 2024
- Source code can be found here:
code-vault.net/lesson/c5746b1...
===== Support us through our store =====
code-vault.net/shop
===== Check out our website =====
code-vault.net
===== Check out our Discord server =====
discord.code-vault.net
WE BACK LETS GOOO
Hey! I’m glad you’re back, your channel has some of the best C explanations i’ve seen on RUclips, thank you for everything you do!
So happy to see a new video from you! Amazing content - I hope you’ve been well.
I'm doing 42 school and your videos are fire man. I recommend them to other students whenever I can. Thank you for the amazing work you're doing! I'm so happy to see you again, to see that you're all fine and healthy. I can see in the comment that I'm not the only one ;)
So glad you are back! Your video series helps me a lot!
good to see you back!
all the best!
Thank you for this playlist 🙏
Atlast you are back , Thank You Sir providing amazing content.
I had this question but now I understand it clearly! Thank you very much!
Nice, happy to see ya making videos again
So happy to see you back
Awwwww 🤗
so good to see you again...
Another great explanation
THE GOAT IS BACK
Nice explanation
keep them coming ;-)
ubb computer science students said thank you sir
Child process continues from the the fork statement,
and what happens to memory is also interesting.
The child gets a copy of all the set values by the parent. Unless the variables are a pointers.
Is that correct?
The child process gets a copy of all variables. Even pointers (although they might not point to what you expect them to)
@@CodeVault I see, thanks, possibly point to the pointer,
to some shared memory which could be dangerous.
@CodeVault when a child is created it will have all lines of code that is below the fork() statement right?
but here fork() is assigned to id and its in the same line . so how does child id gets value 0?
if the child gets all the set values from parent then the id should be +ve ???
Yes, the child process actually is a complete copy of the parent process. All that's different is what fork() actually returns
could you pls explain why this code prints 4 times hello ?
int main() {
int pid, pid2;
pid = fork();
if (pid){
pid2 = fork();
printf("hello");
}
else {
printf("hello");
pid2 = fork();
}
return 0;
}
Well, it should only print "hello" 3 times. Twice in the if(pid) and once in the else block
@@CodeVault I also agree with your point but in some of the online compilers (eg: one compiler) it's actually printing "hello" 4 times. that's why confused.
I tried it myself before replying and it only prints "hello" 3 times. Maybe it's using a previous version of the code?
@@CodeVault that might be the reason