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

Комментарии • 26

  • @JokerTropical
    @JokerTropical Год назад +17

    WE BACK LETS GOOO

  • @nythepegasus
    @nythepegasus Год назад +9

    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!

  • @JakeLuden
    @JakeLuden Год назад +6

    So happy to see a new video from you! Amazing content - I hope you’ve been well.

  • @lorisp186
    @lorisp186 Год назад +2

    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 ;)

  • @alectonz2257
    @alectonz2257 Год назад +1

    So glad you are back! Your video series helps me a lot!

  • @hectordoyle4718
    @hectordoyle4718 Год назад +3

    good to see you back!
    all the best!

  • @nishadkanago4393
    @nishadkanago4393 4 месяца назад

    Thank you for this playlist 🙏

  • @animeshsarkar295
    @animeshsarkar295 Год назад

    Atlast you are back , Thank You Sir providing amazing content.

  • @obscuredbyclouds1209
    @obscuredbyclouds1209 Год назад

    I had this question but now I understand it clearly! Thank you very much!

  • @thefossenjoyer3346
    @thefossenjoyer3346 Год назад

    Nice, happy to see ya making videos again

  • @angelomarzocchi4202
    @angelomarzocchi4202 Год назад

    So happy to see you back

  • @attituderecord7589
    @attituderecord7589 Год назад

    Awwwww 🤗
    so good to see you again...
    Another great explanation

  • @jadl8926
    @jadl8926 Год назад +2

    THE GOAT IS BACK

  • @avatoruncharted1420
    @avatoruncharted1420 Год назад

    Nice explanation

  • @dimitrioskalfakis
    @dimitrioskalfakis Год назад

    keep them coming ;-)

  • @mateicojo4879
    @mateicojo4879 11 месяцев назад

    ubb computer science students said thank you sir

  • @vilijanac
    @vilijanac Год назад

    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?

    • @CodeVault
      @CodeVault  Год назад

      The child process gets a copy of all variables. Even pointers (although they might not point to what you expect them to)

    • @vilijanac
      @vilijanac Год назад

      @@CodeVault I see, thanks, possibly point to the pointer,
      to some shared memory which could be dangerous.

  • @abhijitarun2415
    @abhijitarun2415 4 месяца назад

    @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 ???

    • @CodeVault
      @CodeVault  4 месяца назад

      Yes, the child process actually is a complete copy of the parent process. All that's different is what fork() actually returns

  • @tendulkarzone8463
    @tendulkarzone8463 Год назад

    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;
    }

    • @CodeVault
      @CodeVault  Год назад

      Well, it should only print "hello" 3 times. Twice in the if(pid) and once in the else block

    • @tendulkarzone8463
      @tendulkarzone8463 Год назад

      @@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.

    • @CodeVault
      @CodeVault  Год назад

      I tried it myself before replying and it only prints "hello" 3 times. Maybe it's using a previous version of the code?

    • @tendulkarzone8463
      @tendulkarzone8463 Год назад

      @@CodeVault that might be the reason