How to create child process using fork() || Duplicate Process

Sdílet
Vložit
  • čas přidán 17. 05. 2020
  • In this lecture on how to create child process, you will learn the use of fork system call to duplicate processes. The fork() system call in Linux is used to create a child process or you can say fork() system call is used to duplicate a process. The parent process call fork() which creates a child process. The fork() system all returns the child process ID on success to the parent process and 0 the child process.
    Subscribe - / dextutor
    This lecture is part of the Operating System Lab playlist: • Operating System Lab
    For Program code and more details visit: dextutor.com/fork-system-call/
    Reference Videos:
    1. read write system calls: • read write System Call...
    2. wait system call: • wait System Call Progr...
    3. orphan process: • Orphan Process Program...
    4. zombie process: • Zombie Process Program...
    Tools Required:
    1. Linux environment
    2. Basic knowledge of C Language
    3. gcc compiler installed
    Reference Links:
    Operating System Theory PPTs Link: dextutor.com/courses/operatin...
    Operating System Programs: dextutor.com/courses/operatin...
    Other Playlists:
    OS: • Operating System
    Linux Essential: • Linux Tutorial For Beg...
    RHCSA: • RHCSA Exam Full Course
    Was this tutorial about the fork system call helpful? If so, please share. Let me know your thoughts in the comments.
    #linux #oslab #os #process #fork #dextutor

Komentáře • 43

  • @rampujansharma3440
    @rampujansharma3440 Před 2 lety +11

    i am very grateful to you,,...this is the first time i am posting any comment ...i love you sir ....its really helpful ..i appreciate your service ..god bless you .

    • @dextutor
      @dextutor  Před rokem +1

      Thank's a lot. Glad it helped

  • @Sruthimugle
    @Sruthimugle Před rokem +17

    // here creating a sequence of p-->p1-->p2 parent child using fork
    #include
    #include
    #include
    #include
    int main(){
    pid_t p;
    printf("befor fork
    ");
    p=fork();
    if(p==0)
    {
    pid_t q;
    printf("Inside first fork
    ");
    q=fork();
    if(q==0)
    {
    printf("Iam 2ndchild having id %d
    ",getpid());
    printf("My parent id is %d
    ",getppid());
    }
    printf("Iam child havinf is is %d
    ",getpid());
    printf("My parent id is %d
    ",getppid());
    }
    else{
    printf("My child id is %d
    ",p);
    printf("Iam parent having id %d
    ",getpid());
    }
    printf("common
    ");
    }

  • @believer29
    @believer29 Před rokem +2

    You're a lifesaver sir ! Great explanation

  • @NaveenKumar-cf9di
    @NaveenKumar-cf9di Před 4 lety +4

    bahut wadia explain kita..simple te practical approach

    • @dextutor
      @dextutor  Před 4 lety +1

      Thanks..dextutor.com/cpu-scheduling-algorithms/

  • @nilanjanmajumder8508
    @nilanjanmajumder8508 Před 3 lety +1

    great explanation

  • @kinshipstatus4027
    @kinshipstatus4027 Před 2 lety +2

    such a great tutor , love you sir

    • @dextutor
      @dextutor  Před 2 lety

      Thanks for the support.. Keep sharing

  • @twishanuaichroy1938
    @twishanuaichroy1938 Před rokem +1

    Thanks a lot Sir

  • @saikun0293
    @saikun0293 Před 3 lety +1

    Super!

  • @aishwaryasingla2781
    @aishwaryasingla2781 Před 10 měsíci +1

    Sir in my output in parent block parent id is always printing 1. why is that ? and my outputs are also fixed like first child block is printing and then parent block they are not getting mixed like in yours. Does it have to do something with fact that i am working in zsh bash?

  • @amitgupta2890
    @amitgupta2890 Před 3 lety +1

    good explanation sir
    loved it.

  • @prathyusha3993
    @prathyusha3993 Před rokem

    the code for the exercise:
    if(q==0)
    fork();
    only this part should be added,is this correct sir??

  • @Sruthimugle
    @Sruthimugle Před rokem +1

    sir i have implemented the same code but its showing error near else

  • @ss8273
    @ss8273 Před rokem

    👍👍👍

  • @ashutoshranjan4644
    @ashutoshranjan4644 Před rokem

    Does execution always prefer parent process first?

  • @rampujansharma3440
    @rampujansharma3440 Před 2 lety

    This is code to create child process inside child process

  • @priyeshchaturvedi503
    @priyeshchaturvedi503 Před 2 lety

    please explain ls and ps command using c in system calls

    • @dextutor
      @dextutor  Před 2 lety

      Check the video on exec (Lab 9).. I suppose it would help

    • @dextutor
      @dextutor  Před 2 lety

      Check this link also
      dextutor.com/difference-between-the-working-of-system-and-execl-functions/

  • @siddhantmaharana3936
    @siddhantmaharana3936 Před rokem

    You said q is the pid of the child and fork() returns the value of pid of child. However you said if q==0 is true then it is the child process. Then how is q printed to be 93? Shouldnt it be printing 0?

    • @dextutor
      @dextutor  Před rokem +1

      In child process value of q is 0.
      In parent process the value of q specifies the pid of child.
      There are two process and in each the value of q is different. Go through the video once again to refresh the concept

  • @jananisrisudhakar8261
    @jananisrisudhakar8261 Před rokem +5

    plz use English throughout the video.I don't understand hindi

    • @dextutor
      @dextutor  Před rokem +2

      Hindi part is just a repetition of whats said in english. So shd not be much of an issue.

    • @jananisrisudhakar8261
      @jananisrisudhakar8261 Před rokem

      @@dextutor thanks for clarification😇

  • @745_riyasaha8
    @745_riyasaha8 Před 2 lety +1

    sir can u please share the last que's solution its bit confusing and can u please explain with 2 3 examples .....that will be very helpful

    • @dextutor
      @dextutor  Před 2 lety +1

      Check the video on Solved Practice Problems.. That will help

  • @Preeti606_7
    @Preeti606_7 Před 3 lety

    Where are more videos???? Only 11 videos i could find....plz upload more!

    • @dextutor
      @dextutor  Před 3 lety +2

      More videos will be uploaded in upcoming days

    • @Preeti606_7
      @Preeti606_7 Před 3 lety

      @@dextutor sir I m waiting eagerly.... please upload it soon :)

    • @dextutor
      @dextutor  Před 3 lety +5

      14 now :-)

  • @anandchaudhari1483
    @anandchaudhari1483 Před rokem

    i am getting different id at some time and same id at some time. for same program like
    before fork
    PARENT My child's id is 3025
    PARENT I am parent having id 3024
    Common
    CHILD I am child having id 3025
    CHILD My parent's id is 1461
    Common
    PLEASE EXPLAIN

    • @dextutor
      @dextutor  Před rokem

      The Parent finished before the chiod thus making it orphan.. Do watch next videos also the concept will become clear

    • @anandchaudhari1483
      @anandchaudhari1483 Před rokem

      @@dextutor okk sir.... I was so confused .watched lots of vidios . But now I understood completely

  • @chandanmandal5394
    @chandanmandal5394 Před 3 lety

    kumar

  • @kumudzimal9926
    @kumudzimal9926 Před 3 měsíci

    Nahi samjha