Recent Post

Fork System Call

The purpose of fork() is to create a new process which becomes child process of the caller.
After a new child process is created , both process will execute the next instruction following the fork system call.
Therefore , we have to distinguish the parent from the child.This can be done by testing the returned value of fork().
Fork is a system call which is used to create a child process.
The fork() returns a negative value if the child creation is unsuccessful.
The fork() returns the value zero to the newly created child process.
The fork() returns the positive integer the process id of the child process to the parent process.




 
Fork() System Call Implementation:-

Main()
{
int pid;
pid=fork();
if (pid<0)
{
printf("child process creation is failed");
}
else if(pid==0)
{
printf("child process");
}
else
{
printf("parent process")'
}
}

Example:-

main()
{
fork()
printf("Hello");
}

Conclusion:-

If the program contains n fork calls it will create
2n-1 child process.
when the child process is created by using fork system call , both parent and children will have-
1) Relative Address- Same for both parent & child process.
2) Absolute Address-different for both parent & child process

No comments