How to create child process using fork() || Duplicate Process
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
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 .
Thank's a lot. Glad it helped
// 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
");
}
You're a lifesaver sir ! Great explanation
bahut wadia explain kita..simple te practical approach
Thanks..dextutor.com/cpu-scheduling-algorithms/
great explanation
such a great tutor , love you sir
Thanks for the support.. Keep sharing
Thanks a lot Sir
Super!
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?
good explanation sir
loved it.
the code for the exercise:
if(q==0)
fork();
only this part should be added,is this correct sir??
sir i have implemented the same code but its showing error near else
👍👍👍
Does execution always prefer parent process first?
No
This is code to create child process inside child process
please explain ls and ps command using c in system calls
Check the video on exec (Lab 9).. I suppose it would help
Check this link also
dextutor.com/difference-between-the-working-of-system-and-execl-functions/
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?
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
plz use English throughout the video.I don't understand hindi
Hindi part is just a repetition of whats said in english. So shd not be much of an issue.
@@dextutor thanks for clarification😇
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
Check the video on Solved Practice Problems.. That will help
Where are more videos???? Only 11 videos i could find....plz upload more!
More videos will be uploaded in upcoming days
@@dextutor sir I m waiting eagerly.... please upload it soon :)
14 now :-)
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
The Parent finished before the chiod thus making it orphan.. Do watch next videos also the concept will become clear
@@dextutor okk sir.... I was so confused .watched lots of vidios . But now I understood completely
kumar
Nahi samjha