L-1.8: Fork System call with Example | Fork() system call questions

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.พ. 2025

ความคิดเห็น • 1K

  • @Heythereee998
    @Heythereee998 4 ปีที่แล้ว +750

    Our education system needs more teachers like him!

  • @samiralam244
    @samiralam244 3 ปีที่แล้ว +123

    So we are going in the university just to mark attendance and pay the fee and getting education for free here. Thank you so much. lots of love from #NEPAL

  • @ayushpandey751
    @ayushpandey751 ปีที่แล้ว +12

    🎯 Key Takeaways for quick navigation:
    00:01 📚 Introduction to Fork System Call
    02:03 🔄 Return Values of Fork System Call
    03:34 🖨️ Demonstration of Fork with One Call
    05:31 🌳 Multiple Fork Calls and Process Generation
    08:08 📊 Summary and Key Takeaways
    Made with HARPA AI

  • @amitjamra1583
    @amitjamra1583 4 ปีที่แล้ว +113

    ONE OF THE BEST TEACHER OUT THERE ❤️ ,VERY HONESTLY SPEAKING ,I DON'T USUALLY COMMENT ON A TH-cam VIDEO BUT SIR YOU TEACHES WITH SUCH EASE❤️❤️❤️❤️❤️❤️

    • @Shubham-ui5yy
      @Shubham-ui5yy 3 ปีที่แล้ว +1

      English sudhaar amit you teaches nhi likhte gdhe

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

      @@Shubham-ui5yy chill bro😂🙌

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

    1) B
    As n=a and a=4. so 2^4=16
    2) A
    if condition is satisfied and fork is one time. n=1. Therefore 2

  • @Ritz...00782
    @Ritz...00782 2 หลายเดือนก่อน

    🎯 Key points for quick navigation:
    00:01 *🛠️ Introduction to Fork System Call*
    - Explanation of the fork system call for creating a child process.
    - Use of fork in the C programming context, creating a clone of the parent process.
    - Differences between creating a new process with fork and using threads.
    02:03 *📜 Fork System Call Behavior and Return Values*
    - When a fork is invoked, it returns a value that indicates the process context (child, parent, or error).
    - Child process identified by zero, parent by a positive number.
    - Discussion on scenarios leading to failure (-1) and expected outcomes.
    03:05 *🔄 Fork Execution Sequence*
    - Description of how multiple fork calls impact process executions.
    - Forking leads to multiple parallel "Hello" print outputs.
    - Example illustrating fork mechanism with two forks resulting in multiple processes.
    06:02 *➗ Process Count with Multiple Forks*
    - Calculation of the total number of process prints and child processes.
    - Formula: 2^n total processes and 2^n - 1 child processes per n fork calls.
    - Emphasis on understanding "Hello" print count and process hierarchy.
    Made with HARPA AI

  • @GamerGabbar
    @GamerGabbar 5 ปีที่แล้ว +44

    You're an savior honestly. I don't live in India and my hindi isn't the best but you still manage to do an amazing job. Thanks for making videos like this.

  • @pranavrr7993
    @pranavrr7993 3 ปีที่แล้ว +114

    For my dear friends, who is searching answer for 2nd question, there is a detailed explanation of this question in the next video of this playlist.

  • @yogesh-thetechnicalguy5478
    @yogesh-thetechnicalguy5478 4 ปีที่แล้ว +4

    Best Explanations of fork() system call and numerical explanation.

  • @divyaanshuagrawal3383
    @divyaanshuagrawal3383 ปีที่แล้ว +131

    Make Fork Tree and count the total number of nodes at last level! OR for 4 times a, it will be 2^4=16 times (15 Child Processes, 1 Parent Process).

  • @musicbytushar
    @musicbytushar ปีที่แล้ว +26

    Farishta hai ye bnda...
    He has got countless number of blessings...
    Live long sir ❤️🌹🧿

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

    MCQ Solution : th-cam.com/video/uMMvYLB4cys/w-d-xo.html

  • @letswalk4168
    @letswalk4168 6 ปีที่แล้ว +25

    sir today i saw your lecture about fork and then after i solved a question of fork which is asked in 2019 .it was so simple that it took only few seconds .before that i was unable to solve this question.thank you sir for your amazing explanation.

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

      What is the answer of 2nd question. Can you help me?

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

      4@@manishbadgotra

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

      @@67_rohitraj54 thankyou for helping

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

    Really, Our Education system needs teacher like you...I Salute you Sir👏👏👏

  • @itssaim1745
    @itssaim1745 3 ปีที่แล้ว +5

    For parent (ye to hoga hi) This line of yours reminds me the whole method of fork(). Thank you sir g.

  • @indiandrums8591
    @indiandrums8591 4 ปีที่แล้ว +25

    Because of this type of teachers, I get inspiration to continue higher studies

  • @jesnarizwanarakkal
    @jesnarizwanarakkal 5 ปีที่แล้ว +31

    Awesome.. Thank u sir. How could someone dislike such a wonderful session.. Really u r amazing

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

    mein to sir ke teaching ka fan bante ja raha hun ....love from bottom of my heart

  • @salilshukla2686
    @salilshukla2686 5 ปีที่แล้ว +17

    Sir u teach every topic with great enthusiasm. 👍👍👍👏👏

  • @wanifirdoos1737
    @wanifirdoos1737 6 ปีที่แล้ว +14

    Sir Ur Way Of teaching is amazing ....May God bless u ....

  • @sajjadjamil1765
    @sajjadjamil1765 5 ปีที่แล้ว +13

    Great teacher. Salute you from pakistan

  • @munmunkumar5546
    @munmunkumar5546 5 ปีที่แล้ว

    Saandaar, jaandaar,Jabardast,jindabaad... gurudev ki jay.

  • @ShivAdiShakti108
    @ShivAdiShakti108 6 ปีที่แล้ว +12

    Thank You.. Thank You Sir! You accepted my request on videos for Fork() system call. I am so grateful to you.

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

    masha ALLAH well sir topic ap ny esy smjaya jesy mahkan hota hai

  • @jawadaslam8537
    @jawadaslam8537 3 ปีที่แล้ว +6

    well explained Sir... We need teachers like you in out university that we are lacking now

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

    Best education on youtube. With your education we can understand everything.

  • @nikitanath1001
    @nikitanath1001 5 ปีที่แล้ว +24

    Answer (B) 16..
    Tnx for clear explanation sir..thank u so much...😊😊

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

    I think no one can forget the output of fork after such explanation.. Thanks a lot sir...

  • @poojanirala3071
    @poojanirala3071 6 ปีที่แล้ว +5

    Thank you sir for this part.... I was waiting for this...

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

    It's very important lecture for me thanku so much sir bht hi acha explain Kiya apne

  • @bidishagoswami3629
    @bidishagoswami3629 6 ปีที่แล้ว +4

    Keep up the good work Sir👌thank u

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

    Informative Video🙏🙏

  • @shawnidutta4397
    @shawnidutta4397 6 ปีที่แล้ว +16

    This video is really really great sir. You are doing great work for us. It will be a great help if you start a series on Artificial Intelligence and software engg according to UGC NET new syllabus. I think many people will be grateful to you. Thank you in advance sir.

  • @InaidKhalid-di1wn
    @InaidKhalid-di1wn ปีที่แล้ว

    Gate smashers bhai sabse accha teacher hain class ka DBMS kuch samajh mein ata hi nhi tha aapke video dekh ne ke baad dbms ka concept pura samajh mein aya aisha padhate raho sir love you ❤❤❤ ❤

  • @sarmadnadeem_
    @sarmadnadeem_ 5 ปีที่แล้ว +3

    MashAllah

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

    example de kr aap ne samjhaya , uske liye bahut bahut Thank you sir. Ab nahi bhulungi

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

    9:53
    child processes - 15
    It will print 16 times

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

      can you explain pls

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

      @@khushal3418 with the formula....
      2^4 -1 children and 1 parent
      4 because loop runs 4 times

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

      correct

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

      hyy what is the ans for the 2nd question, i see no one has commented it?

    • @calisthenics5247
      @calisthenics5247 11 หลายเดือนก่อน +2

      ​@@yujibestboiit should be 2

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

    Very good explanation sir.

  • @sidharthmandal9957
    @sidharthmandal9957 6 ปีที่แล้ว +9

    Thank you very much sir. Lots of respect to you.
    My concepts got clear by watching your video.
    Searched everywhere to understand but couldn't.
    Tysm.#

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

    Sir I am the biggest fan of u. Sir I am a bca student.and I learn every course u provide like CN,OS,DBMS,

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

    Forking amazing 🔥

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

    👏 HatsOff to you sirji ....4 years Ki Study me ye topic nahi samja but today I understand it very well...kash aap pehle milte... You are the Best teacher

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

    cant thank you enough... Have been struggling for this since two days. I could understand this perfectly. Thank you so much

    • @RAJ-np1iu
      @RAJ-np1iu 3 ปีที่แล้ว

      @Vasudha Pasumarthi can you tell from where are you preparing for DEC?

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

    sir gajab padhate hai ....
    every topic crystal clear 😍

  • @GopalOswal
    @GopalOswal 3 ปีที่แล้ว +15

    now a days getting college degree is just a fun but getting knowledge from such teacher is fruitful 😛
    keep going sir
    students like me need more content 😅😅

  • @Engineer78206
    @Engineer78206 6 หลายเดือนก่อน +2

    good explanation :)

  • @akankshasharma6423
    @akankshasharma6423 4 ปีที่แล้ว +8

    Wow! U have explained the concept in such an amazing manner. Thank you 😊

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

    Besttt🎉🎉🎉🎉

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

    In the parent process, the value of pid after calling fork() will be the process ID (PID) of the newly created child process. The pid variable will contain the PID of the child process, allowing the parent process to identify and potentially interact with the child process using this PID.

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

    best engineering channel on youtube.great sir g

  • @piyushsharma1360
    @piyushsharma1360 3 ปีที่แล้ว +156

    4 times loop run so 4 times fork command executed and result comes out to be 16 option(b)

    • @yash.gupta_
      @yash.gupta_ 2 ปีที่แล้ว +2

      Wrong

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

      @@yash.gupta_ so what's the answer man

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

      @@subscribeinsteadlike2768 30

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

      @@voidofficial6525 you are wrong answer is 16 bro

    • @111rhishishranjan2
      @111rhishishranjan2 2 ปีที่แล้ว +10

      @@prathamgupta6973 ANSWER IS 16 AS THE FOR LOOP WILL RUN 4 TIME FROM 1 TO 4 SO 4 TIMES AND 2^4 =16 SHOULD BE THE ANSWER.

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

    1. 16 correct
    2. 2 is correct
    Thank you so much sir for provide such kind of contents 😊😊

    • @ManinderSingh-xr6ir
      @ManinderSingh-xr6ir 2 ปีที่แล้ว +1

      1 is correct but i doubt the second one. some are saying 4 is the answer of 2nd question

    • @md.shakilahmed1271
      @md.shakilahmed1271 2 ปีที่แล้ว +1

      I think it will 2

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

    AOA guys I am from Pakistan, he is one of the best and my favorite teacher,,.

  • @BhagyaRana
    @BhagyaRana 4 ปีที่แล้ว +13

    Q1 : 16 times Print 1
    Q2 : 4 Times Print Hello

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

      Can you please explain Q2's answer

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

      Pls explain Q2... I beg 😭😭😭😭😭😭😭😭😭😭😭😭

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

      @@Arceus948 ​ @Mrudula Rothe P -> {C1, P} -> {C2, C1, C3, P} Therfore, 1 Parent & 3 Child, So 4 Times "Hello" Will be Printed.

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

      @@BhagyaRana ok thnx 😀👍🏻

  • @think_positive11
    @think_positive11 5 ปีที่แล้ว

    Awsm teaching method ...... Grt job

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

    ques 1: B
    ques 2: A

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

    Very useful vedio sir 🙏🙏👍👍

  • @Meander_Man
    @Meander_Man 4 ปีที่แล้ว +43

    a goes from 1 to 4, so Total 4 times fork is called so "1" is printed 2^(4) = 16 times. There will be 15 child process and 1 parent process

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

    nice video! thank u sir

  • @sairamdonthula7827
    @sairamdonthula7827 5 ปีที่แล้ว +13

    B-16 times "1" is printed

  • @sharmavaibhav260
    @sharmavaibhav260 4 ปีที่แล้ว +54

    it will print "hello" 4 times.
    p
    / \
    (Fork()=0) c1 p(fork()=1)
    / \
    c2 p
    / \
    c3 p
    :- c1+c2+c3+p = 4 times "hello"

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

      Is this right?

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

      YES

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

    great teaching

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

    sir obviously 16 becasuse of 2^4 here n=5 -1=4 from loop, 15= child and 1= parent

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

    excellant sir...

  • @comradepeter87
    @comradepeter87 4 ปีที่แล้ว +5

    16 and 4? Whatever be the answer, you're an awesome teacher! I'm a high-schooler and even I could understand this!

    • @chocochips-as
      @chocochips-as 4 ปีที่แล้ว

      sahi ha bhai

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

      pls explain ans of 2nd ques

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

      @Sajib Saha But if fork() methods in if block returns +ve value it means they have created a child process, then there are 3 fork() statements executed, So what will be the answer now?

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

      The answer would be 4, because fork() method return return both 0 and 1,one after another, then there will be 4 cases in if block 00, 01, 10, 11. In 2nd and 3rd condition fork() method creates a child process and execute printf statement one after one. And in last case when fork() methods will return 1, then the inner fork() method will create a child process and a parent process. Thus, 4 times printf statement will be executed.

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

      @Sajib Saha But what about fork() in if block, as condition of if block is also a fork() method, whether the condition satisfies or not, fork() in condition parentheses will be executed, I am not talking about fork() just after if block, I am talking about fork() in the condition of if block

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

    Great job

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

    16 times 1 will be printed because the formula mentioned by sir is 2^n for how much time the program is executed .
    (2-1) ^ n for how many child processes created
    Watch the video to get full easy and easy explanation
    Thank you sir

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

    One of the best teacher in india 🇮🇳

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

    Sir whatever you said was alright and you explained everything well but kindly tell us that what is practical importance of this call and when to use this . What will be the advantage of creating a child process ? In actual practise i dont think we will be required to do same thing n number of times. Thank you .

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

    great explaination

  • @amargandhi1137
    @amargandhi1137 5 ปีที่แล้ว +3

    Sir
    Your way of teaching is awesome
    I wish you to God fill your all desire
    Sir can please provide me viedoes ipc mechanism

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

      Thank you so much..lots of love and blessings

  • @ig5565
    @ig5565 6 ปีที่แล้ว +3

    sir plz NET k liye b subjct wise videos provide kr dijiye according to the schedule u provided...

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

    Very nice

  • @akhilyadati6103
    @akhilyadati6103 3 ปีที่แล้ว +44

    Answer for the question at last is 2⁴=16 option B as loop rotates 4 times .

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

    most respect from Pakistan
    Syed tehzeeb Haider

  • @shivansh_kr._
    @shivansh_kr._ 3 ปีที่แล้ว +3

    16 times "1" will be printed (15 child nodes and 1 main node)

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

    very good explanation

  • @Mukeshbabu789
    @Mukeshbabu789 6 ปีที่แล้ว +4

    sir... 50k hone wala h SUBSCRIBERS. .....haha SILVER play button ke sath new chapter of UGC-NET ka start kar dena bcoz exam ki DATESHEET aa gaye h..PLZZZZZZZZZZZZZZ

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

    Nice video sir

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

    In the starting part of the video you mentioned that child process is created when the parent is busy or not available to execute the process but in the latter part of the video you were teaching that both the child and parent process work simultaneously, then what is the need for creating child process?

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

    Thanks for sharing knowledge

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

    Answer of question 1 asked in the end will be "option B" i.e. "16" (2^4 because loop will be executed 4 times)

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

    Awesome!

  • @surojitkarmakar9904
    @surojitkarmakar9904 6 ปีที่แล้ว +4

    Please make a video that how os interact with processor...

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

    Sir Very best Explanation

  • @sashankpindiproli8778
    @sashankpindiproli8778 4 ปีที่แล้ว +6

    Amazing explanation!! Maybe you could have mapped the fork to tree data structure and explained why it is 2^n.

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

    Superb

  • @FRIENDSForever-hh7dh
    @FRIENDSForever-hh7dh 5 ปีที่แล้ว +6

    love from Pakistan

    • @GateSmashers
      @GateSmashers  5 ปีที่แล้ว +5

      Lots of love and blessings from INDIA

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

    Great explanation ...

  • @taranpreetsingh7366
    @taranpreetsingh7366 3 ปีที่แล้ว +8

    sir, does it make a difference if we write
    main()
    {
    fork();
    printf("HELLO");
    fork();
    }

    • @Gurtej-hf1fj
      @Gurtej-hf1fj 11 หลายเดือนก่อน

      it will not work, and will give output of (Hello Hello)

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

    Very much helpful and easy to understand

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

    answer the video question
    Q1 -option(B) 16
    Q2 -option(C) 4

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

      please explain Question.1> how it is 16?

  • @ishaabid4081
    @ishaabid4081 4 ปีที่แล้ว +6

    Question 1:16 times.
    Question 2: 4 times

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

    Great sir

  • @shubhamkumar-se7sr
    @shubhamkumar-se7sr 4 ปีที่แล้ว +3

    Hii @Gate Smashers the video was good but you didn't tell why the fork system call is needed. Yes to create Child Process with the same capability as of parent but what kind of problem does fork system call solve?

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

    Very nice🎉🎉🎉💯

  • @computerworldwithnaman4560
    @computerworldwithnaman4560 4 ปีที่แล้ว +6

    fork() function is executing 4 times so total 2 to power 4= 16 process will create including main process
    all 16 process will execute printf("1")
    so 1 will print 16 times in output
    Ans (B) 16

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

      32. dwar diagram n will understand

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

    Your teaching is awesome sir 👌👌

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

    Make a series for "System Analysis & Design".
    Excellent Explanation - Thanks "Keep on the good work".

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

    Nice sir aap Awesome hooo❤❤❤❤❤❤❤