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

Поделиться
HTML-код
  • Опубликовано: 17 май 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

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

  • @rampujansharma3440
    @rampujansharma3440 Год назад +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  Год назад +1

      Thank's a lot. Glad it helped

  • @Sruthimugle
    @Sruthimugle Год назад +14

    // 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 Год назад +2

    You're a lifesaver sir ! Great explanation

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

    great explanation

  • @NaveenKumar-cf9di
    @NaveenKumar-cf9di 4 года назад +4

    bahut wadia explain kita..simple te practical approach

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

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

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

    Thanks a lot Sir

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

    such a great tutor , love you sir

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

      Thanks for the support.. Keep sharing

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

    Super!

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

    good explanation sir
    loved it.

  • @aishwaryasingla2781
    @aishwaryasingla2781 7 месяцев назад +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?

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

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

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

    👍👍👍

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

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

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

    Does execution always prefer parent process first?

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

    please explain ls and ps command using c in system calls

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

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

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

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

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

    This is code to create child process inside child process

  • @745_riyasaha8
    @745_riyasaha8 2 года назад +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  2 года назад +1

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

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

    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  Год назад +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

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

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

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

      More videos will be uploaded in upcoming days

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

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

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

      14 now :-)

  • @jananisrisudhakar8261
    @jananisrisudhakar8261 Год назад +4

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

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

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

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

      @@dextutor thanks for clarification😇

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

    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  Год назад

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

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

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

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

    kumar

  • @kumudzimal9926
    @kumudzimal9926 29 дней назад

    Nahi samjha