Process IDs in C

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 เม.ย. 2020
  • Check out our Discord server: / discord

ความคิดเห็น • 94

  • @sarahmedouni8844
    @sarahmedouni8844 ปีที่แล้ว +18

    no child left behind

  • @nininachkebia501
    @nininachkebia501 3 หลายเดือนก่อน +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!!!

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

  • @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!

  • @Mutechnoo
    @Mutechnoo ปีที่แล้ว +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!

  • @jaysechase
    @jaysechase 2 ปีที่แล้ว +4

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

  • @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 TH-cam !

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

  • @wick6296
    @wick6296 4 ปีที่แล้ว +1

    Crazy content lately. Keep it up ! Thank you

  • @bama2619
    @bama2619 3 ปีที่แล้ว +1

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

  • @fabiozucconi7068
    @fabiozucconi7068 7 หลายเดือนก่อน

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

  • @mikey58291
    @mikey58291 ปีที่แล้ว +2

    This series is an absolute gem.

  • @erozgiordano320
    @erozgiordano320 3 ปีที่แล้ว

    These videos are gold, thank you so much

  • @NOPerative
    @NOPerative 4 ปีที่แล้ว

    The res block brought everything together; excellent work!

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

  • @georgioziozas9031
    @georgioziozas9031 3 ปีที่แล้ว

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

  • @manelbel6490
    @manelbel6490 2 ปีที่แล้ว

    I really like your work thank you so much 🙏🏽

  • @tiwaritejaswo
    @tiwaritejaswo ปีที่แล้ว

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

  • @Clarin3t1
    @Clarin3t1 2 ปีที่แล้ว

    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.

  • @sony1979iq
    @sony1979iq 3 ปีที่แล้ว

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

  • @senamione
    @senamione 3 ปีที่แล้ว

    Thank you for your videos!

  • @AnimalKingdom2510
    @AnimalKingdom2510 2 ปีที่แล้ว

    its 2021 and im finding these videos really helpful..

  • @americobaptista3499
    @americobaptista3499 3 ปีที่แล้ว

    Life saver series! Thanks

  • @vinayak186f3
    @vinayak186f3 2 ปีที่แล้ว

    This channel is gem

  • @esmondadjei
    @esmondadjei ปีที่แล้ว +1

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

  • @mahfuzuddin4545
    @mahfuzuddin4545 2 ปีที่แล้ว

    bless these videos

  • @vambans2412
    @vambans2412 4 ปีที่แล้ว

    Great course

  • @Yackkimani
    @Yackkimani 3 ปีที่แล้ว

    thank you so much

  • @imwritingapoemaboutit
    @imwritingapoemaboutit 3 ปีที่แล้ว

    god bless you man

  • @moi259
    @moi259 ปีที่แล้ว

    Thank You :)

  • @nere_els
    @nere_els 6 หลายเดือนก่อน

    thank you so much

  • @rakinar2
    @rakinar2 ปีที่แล้ว

    I loved this video!

  • @avishekdutta1901
    @avishekdutta1901 3 ปีที่แล้ว

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

  • @abdulhadialdahan1328
    @abdulhadialdahan1328 หลายเดือนก่อน

    This is interesting that every process has a parent save for 0 so I guess 0 is the kernel or something ? I guess I would find out next semester with the dreadful Operating System course 😂

  • @kavalan9588
    @kavalan9588 3 หลายเดือนก่อน

    Great

  • @abdelrahmanal-mokhraty9198
    @abdelrahmanal-mokhraty9198 3 ปีที่แล้ว

    you are so GREAT

  • @VintageTups
    @VintageTups 4 ปีที่แล้ว +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  4 ปีที่แล้ว +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.

  • @narendraparmar1631
    @narendraparmar1631 3 ปีที่แล้ว

    Thanks

  • @radmehrtalebi6818
    @radmehrtalebi6818 27 วันที่ผ่านมา

    God bless you

  • @vambans2412
    @vambans2412 4 ปีที่แล้ว +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  4 ปีที่แล้ว +11

      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.

  • @ZakiFootballVideos
    @ZakiFootballVideos 3 ปีที่แล้ว

    thank you

  • @sebastianespin6114
    @sebastianespin6114 3 ปีที่แล้ว

    thanks

  • @_SeaH0rse
    @_SeaH0rse ปีที่แล้ว +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

    • @_SeaH0rse
      @_SeaH0rse ปีที่แล้ว

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

  • @onlytheflames
    @onlytheflames 2 ปีที่แล้ว +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  2 ปีที่แล้ว +1

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

  • @natetolbert3671
    @natetolbert3671 3 ปีที่แล้ว

    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  3 ปีที่แล้ว

      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

  • @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!

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

  • @akshyagarg2398
    @akshyagarg2398 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

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

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

  • @suneelabbigari
    @suneelabbigari 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

      I will look into this and make a video about it

    • @suneelabbigari
      @suneelabbigari 3 ปีที่แล้ว

      @@CodeVault Thank you

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

  • @janasawalmeh7840
    @janasawalmeh7840 8 หลายเดือนก่อน

    What is the app u use to write the code?

    • @CodeVault
      @CodeVault  8 หลายเดือนก่อน

      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

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

  • @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 :)

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

  • @saurav8967
    @saurav8967 9 หลายเดือนก่อน +1

    ye mera tshirt hai kal se mt paheniyega

  • @letthegamebegin4306
    @letthegamebegin4306 11 หลายเดือนก่อน

    @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  11 หลายเดือนก่อน

      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

  • @kiseijuu7420
    @kiseijuu7420 4 หลายเดือนก่อน

    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.

    • @flaviohenrique5294
      @flaviohenrique5294 3 หลายเดือนก่อน

      man of the fork say about the return of the fork function:
      " 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 to indicate the error."

    • @CodeVault
      @CodeVault  3 หลายเดือนก่อน

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

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