Process IDs in C

Поделиться
HTML-код
  • Опубликовано: 27 апр 2020
  • Check out our Discord server: / discord

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

  • @sarahmedouni8844
    @sarahmedouni8844 Год назад +7

    no child left behind

  • @Ahmad-ej2fy
    @Ahmad-ej2fy 4 года назад +90

    this is very useful for CS students, you are handling very important content and hidden things that are not shown in other videos in youtube

  • @nininachkebia501
    @nininachkebia501 4 дня назад

    i'm here after 4 years and i just have to say that you saved me! i was attending every lecture in uni but still couldn't fully grasp the idea of muliprocess creation until i watched these videos!!! now i feel calm that i actually fully understand it and am not only learning it for the midterm!!!

  • @ericvinogradov2048
    @ericvinogradov2048 Год назад +5

    This is one of the clearest and most in depth videos I've been able to find on the topic, and has helped me tremendously with my studying. Thank you so much!

  • @cameronjoyner1
    @cameronjoyner1 3 года назад +28

    Completely agree with Ahmed. I'm using this to study for an exam in C programming. Great content! Please make more!

  • @jaysechase
    @jaysechase 2 года назад +4

    Learning more tonight with your videos than I did in my whole Client Server course! No joke!

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

    This series is an absolute gem.

  • @wick6296
    @wick6296 4 года назад +1

    Crazy content lately. Keep it up ! Thank you

  • @sebas041296
    @sebas041296 4 года назад

    I love you, i love the quality of your videos, it makes it so much easier to understand that a lot of videos out there

  • @zaabimahdi
    @zaabimahdi 4 года назад

    you are takinng the channel to another dimensions !
    not only crazy content but i think the most original content about c i've ever seen on RUclips !

  • @bama2619
    @bama2619 2 года назад +1

    Thank you. Clear enough but I need to practice to see the IDs to understand more. Great job, sir!

  • @NOPerative
    @NOPerative 3 года назад

    The res block brought everything together; excellent work!

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

    this channel is pure gold, keep on making these fantastic videos!

  • @erozgiordano320
    @erozgiordano320 2 года назад

    These videos are gold, thank you so much

  • @georgioziozas9031
    @georgioziozas9031 3 года назад

    Congrats for your videos and detailed explanation brother. You help a ton.

  • @t_rm2119
    @t_rm2119 3 года назад +5

    thank you so much. we are doing this in OS and even tho C should be known which i do but we never mentioned stuff like fork, pid, ppid and they somehow expected us to know this already .

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

    Literally no other resource on youtube as good as this. Thanks 🙏

  • @manelbel6490
    @manelbel6490 2 года назад

    I really like your work thank you so much 🙏🏽

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

    These videos are AMAZING! THANK YOU!!!

  • @nikhilkothari6303
    @nikhilkothari6303 3 года назад

    Thank you so much, this video was really helpful to handle the program with multiple children and controlling its execution with help of wait and sleep.

  • @americobaptista3499
    @americobaptista3499 3 года назад

    Life saver series! Thanks

  • @AnimalKingdom2510
    @AnimalKingdom2510 2 года назад

    its 2021 and im finding these videos really helpful..

  • @sony1979iq
    @sony1979iq 2 года назад

    thank you for this serie of c programming, really like it: continue with good job.. thx one more time

  • @senamione
    @senamione 2 года назад

    Thank you for your videos!

  • @mahfuzuddin4545
    @mahfuzuddin4545 2 года назад

    bless these videos

  • @imwritingapoemaboutit
    @imwritingapoemaboutit 3 года назад

    god bless you man

  • @vinayak186f3
    @vinayak186f3 2 года назад

    This channel is gem

  • @Yackkimani
    @Yackkimani 3 года назад

    thank you so much

  • @vambans2412
    @vambans2412 3 года назад

    Great course

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

    Great content prof! Wished I could fork my brain 😆🧠

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

    thank you so much

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

    Thank You :)

  • @avishekdutta1901
    @avishekdutta1901 3 года назад

    Your videos are very useful......Plzz make more videos on OS..

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

    High quality content as always.
    Permit me a silly question, if the child process ID is meant to be 0. how come those processes have IDs other than zero?

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

      You are misunderstanding what fork() actually returns. I see this quite often in the comments therefore I made a video explaining the answer for your question here: code-vault.net/lesson/c5746b15bc917ba13615a0ec8c0011c1

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

      @@CodeVault Thank you very much, and Ill join the discord too

  • @kavalan9588
    @kavalan9588 4 дня назад

    Great

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

    I loved this video!

  • @abdelrahmanal-mokhraty9198
    @abdelrahmanal-mokhraty9198 3 года назад

    you are so GREAT

  • @VintageTups
    @VintageTups 3 года назад +2

    A quick question, 1. What exactly is the difference between the PID and the value returned by the fork?
    2. The fork is the function that is asking to create the child which invokes the new PID, so why can't fork take that value? Why isn't the fork returning the value of the PID itself?

    • @CodeVault
      @CodeVault  3 года назад +7

      Well, fork() returns 2 values, technically. One in the child process (which is always 0) and another one in the parent process (which is the child process' id). If both values would return the child's process id it would be more difficult to distinguish between the child and parent process.
      So if you call getpid() in the parent process after calling fork() you'd get two different values. fork() would return the child's process ID and getpid() would return the parent's process ID.

  • @ZakiFootballVideos
    @ZakiFootballVideos 3 года назад

    thank you

  • @vambans2412
    @vambans2412 3 года назад +2

    Thank you, i have a doubt. Process id of child was zero right but now why getpid gives big value like 1038?

    • @CodeVault
      @CodeVault  3 года назад +10

      Process ids are never 0. Or at least the ones you're working with aren't.
      That 0 is what fork() returns. fork does return the process id in the parent process BUT, in the child process it just returns 0 (not its process id).
      If fork() would return the child process id in both parent and child it would be difficult to check which is which.

  • @natetolbert3671
    @natetolbert3671 2 года назад

    I noticed that Linux jumps through some extra hoops in order to ensure that every process has a parent. Is it safe to assume then, that the parents sort of act as babysitters (hierarchical buddy system of a sort) to ensure that there are no runaway processes running infinite while loops into the night in the background.. sort of like a primitive garbage collection system?
    Btw TYVM. This is the first programming tutorial series I've had the urge to watch e2e in a very long time.

    • @CodeVault
      @CodeVault  2 года назад

      Basically Linux does try and clean up resources automatically but we, as programmers, shouldn't rely on that as it's not necessarily efficient.
      Here's some more info on the topic: unix.stackexchange.com/questions/155012/how-does-linux-handles-zombie-process

  • @narendraparmar1631
    @narendraparmar1631 3 года назад

    Thanks

  • @sebastianespin6114
    @sebastianespin6114 3 года назад

    thanks

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

    Hey i want to ask, what extension are you using to show information about a line of code when you put you cursor on it?

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

      It's just the C/C++ extension from Microsoft. Make sure you configure it properly

  • @suneelabbigari
    @suneelabbigari 2 года назад +1

    Could you please explain what is
    1) init process , when exactly its get created ?
    2) what is daemon process , how it is created ?
    how long they exists in the system ??
    expecting a video on processes that exists on the system side by default ?

    • @CodeVault
      @CodeVault  2 года назад +1

      I will look into this and make a video about it

    • @suneelabbigari
      @suneelabbigari 2 года назад

      @@CodeVault Thank you

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

    I am not sure what happened in 2:53 . The output shows 4 pids . One of them wa printed twice, then that is to say there are there three processes, which I don't get because we called fork() only once there and we are supposed to have only two process (the parent and the child)

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

      I think i have an explanation . When I use getppid() without using fork() for example like in the folloaing code :
      #include
      #include
      int main () {
      printf(" This is the ID of the current process %d and this is the id of its parent %d
      ",getpid(),getppid());
      return(0);
      }
      Here I got as an output two different values. The first one is of my process that I am running . The second one is a parent which could be one of the processes(WindowMaker , xtrem ,bashm inetd...) idk what the operating system done. But that's not important I think I got what I need and this explaines the presence of three different pid in your video!

  • @ScantaniouslyCombust
    @ScantaniouslyCombust 2 года назад +1

    Do you have a video specifically about Zombie processes? It would be good to have a thorough look at what they are.

    • @CodeVault
      @CodeVault  2 года назад +2

      No, there isn't one yet. I'll look into it

  • @akshyagarg2398
    @akshyagarg2398 3 года назад

    Suppose two processes parent and child are running concurrently and OS decides to terminate child process and then come to parent process. S o now if parent process has wait function then will wait function return -1 or what?

    • @CodeVault
      @CodeVault  3 года назад

      No, wait(NULL) would still return the child's process ID since, even though the process terminated, the OS waits for someone to call wait() on it to free some resources the OS allocates for every process. And it knows that the current parent process has a child process that nobody called wait() on.

    • @akshyagarg2398
      @akshyagarg2398 3 года назад

      @@CodeVault got your point. Thanks for the reply. I will share your video with my colleagues. It is very helpful. Thanks

  • @dwarfcoder
    @dwarfcoder 3 года назад

    You are amazing. 😇

    • @CodeVault
      @CodeVault  3 года назад

      Thanks! Feel free to join our discord server if you have any questions and what not: discord.code-vault.net

  • @sonayesayan7830
    @sonayesayan7830 2 года назад

    Thank you for your videos! They're very useful. I have a question: in the previous video you specified wait() exactly for the parent process, so the child will not wait for any process to finish its execution. I don't really understand why it works properly in this case without specifying the process to wait

    • @CodeVault
      @CodeVault  2 года назад +3

      Basically wait(NULL) knows what child processes the current process has. So, if you call wait(NULL) on a process that has no child processes then it just returns instantly as there's nothing for it to do

  • @willisogecha1
    @willisogecha1 2 года назад

    Kindly help me please,
    Are you working with windows Os,
    Or which OS are you using.
    And if not using windows, kindly help me ,How can I use windows to do the same project?

    • @CodeVault
      @CodeVault  2 года назад

      No. I'm using a Linux distribution (Ubuntu) for this video. You could also try installing WSL on Windows but native Linux is easier to set up

  • @iloveukraine-subscribe1kgo822
    @iloveukraine-subscribe1kgo822 3 года назад

    Thank you for the fourth time

  • @janasawalmeh7840
    @janasawalmeh7840 5 месяцев назад

    What is the app u use to write the code?

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

      Visual Studio Code

  • @beef2244
    @beef2244 3 года назад

    What Compiler do you use?

    • @CodeVault
      @CodeVault  3 года назад +1

      The compiler is gcc, the IDE is Visual Studio Code. Here's the video explaining my setup: code-vault.net/course/yx1g2sh6l4:1610029046575/lesson/tv93s6yw9r:1610568955955

    • @beef2244
      @beef2244 3 года назад

      @@CodeVault Thank you

    • @kimkong9391
      @kimkong9391 3 года назад

      @@CodeVault you said child process id always has zero in previous video but in this video we are having non zero as child process id... I'm confused

  • @letthegamebegin4306
    @letthegamebegin4306 8 месяцев назад

    @7:18 if you havnt used wait in parent, it will first finish execution of parent & then it will finish the execution of child !!!! if so why use wait, even if we dont use we will still get the same result !!!

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

      It's important to use it because, without it, the child process might become a zombie process (meaning that its parent child finished its execution already). This forces the operating system to clean up the child process resources. This is not always desired

  • @tiemen88
    @tiemen88 2 года назад

    One question. I thougt you said the child ID was 0 in previous and not 4179 or any other number > 0
    Thank you so much for these videos. Greetings from Codam 42 Network.

    • @CodeVault
      @CodeVault  2 года назад

      fork() returns different things based on the process. It returns 0 in the child process that it just created and it returns *the child's process id* in the parent process
      The actual ID of the parent process you can find by using getpid
      So fork() doesn't return the current process' ID and a process ID can never be 0. Just because fork() returns 0, it doesn't mean that the child process ID is actually 0, that 0 is there so we know which is the child process and which is the parent process in the calling context

    • @tiemen88
      @tiemen88 2 года назад +1

      @@CodeVault Ah yes, I get it. Thanks!

  • @suneelabbigari
    @suneelabbigari 2 года назад

    In the video-2: you said, if the process has no child , and if you have wait() , it will get struck there.

    • @CodeVault
      @CodeVault  2 года назад +1

      Oh! Then it's my mistake. No, what will happen is it will just continue execution since it knows there are no child processes to wait for.

  • @omardumet120
    @omardumet120 2 года назад

    where are you form bro?

  • @kemalfirat4692
    @kemalfirat4692 2 года назад +1

    Hello, i exactly wrote the same code of yours but my result is like what is the problem with that or it is okay? Thank you for videos by the way :) :
    Current id: 3953, parent id: 3952
    No children to wait for
    Current id: 3952, parent id: 3946
    3953 finished execution

    • @CodeVault
      @CodeVault  2 года назад +2

      Looks fine to me. The order of the messages or the actual IDs don't matter in this instance. All that matters is that the messages are correct, and they are. You have 2 processes: 3952 and 3953. 3953 doesn't have to wait for any child processes and 3952 prints out that it waited for 3953

    • @kemalfirat4692
      @kemalfirat4692 2 года назад

      @@CodeVault Alright thank you :)

  • @kiseijuu7420
    @kiseijuu7420 Месяц назад

    I dont get why u first told us that the child process id is 0, then getpid tells us that its something different. When is the child process equal to 0? Is it equal 0 only for the parent? But if its the case, i dont get why the child would enter the « if » then, cause in the child, the id isnt 0 so nobody would go in this « if ».
    It kinda lost me ngl.

    • @CodeVault
      @CodeVault  26 дней назад

      I got this question many times and I made a video regarding this: code-vault.net/lesson/c5746b15bc917ba13615a0ec8c0011c1

  • @saurav8967
    @saurav8967 6 месяцев назад +1

    ye mera tshirt hai kal se mt paheniyega

  • @naitside3410
    @naitside3410 2 года назад

    у меня parent id = 1
    Текущий id:66199, Родительский id: 65033
    Текущий id:66200, Родительский id: 1

    • @CodeVault
      @CodeVault  2 года назад +1

      Make sure you call wait(NULL) here (not wait(id)). While what we use here is working on MacOS the series was made for Linux, I'm not sure about the details when it comes to creating processes in MacOS

  • @agentstona
    @agentstona 2 года назад

    fork doesnt exist on windows ..............WINDOWS USERS THIS IS NOT FOR YOU