Creates a new process( Child process) by using "fork()" function in C

"Fork" system call use for creates a new process, which is called child process.Which runs concurrently with process (which process called system call “Fork”) & this process is called parent process.

Ex-:
There is a program it’s called P1.
P1---à
                main(){
                                    int a=10,b=5;
                    printf(”d“,%a);
                   fork();
                     printf(“%d”,a+b);
                   printf(“%d”,c);
                }


           
Suppose “child1” is child process of p1

After running fork(), P1 creates his child. Suppose it’s name “child1”. Child1 copied all commands below the “fork()” command line in program p1.
            


  Child1 -à
                   printf(“%d”,a+b);
                   printf(“%d”,c);


                child1 doesn’t copy variable “a”. but it know variable a.

after, parents & Childs programs are running concurrently(interrupted the programs)

Comments

Post a Comment

Popular posts from this blog

Operating Systems in Mobile Devices