Featured Post

Saturday, March 26, 2016

process chain using fork() system call

/* creating child processes using fork() system call */



fork():   In UNIX fork() system call is used to create a child process. When a parent process issues a fork() system call there are total two process one is parent and the other is child. After fork() system call either parent process or child process will continue execution  first.



fork() system call return zero if child parent process is executing. fork() system call returns any positive number greater then zero if parent process is executing. fork() system call returns -1 if fails.



Process tree:

    
    If parent process issued fork() system call first time then there are total two processes one is child and another is parent. For example parent process issued another fork() system call then there are total four processes. One parent process, one is new child,another two are from first child process.If parent process issued one more system call the there are 8 process in total one is parent and remaining 7 are child process.

Note: if parent process issues n times fork() system call then there 2 power n process in total. (among then one is parent)


     for example if a parent issued  8 times fork() system call there are total 256 processes among them one is parent and the remaining 255 is child processes.


/* UNIX program to create process tress*/
/*process tree.c*/


#include<stdio.h>

#include<unistd.h>
#include<fcntl.h>
void main()
{
    fork();
    fork();
    fork();
   printf("\ hello ");/* hello will be printed total 8 times */
}



Output:



/home/anil/~$ cc processtree.c

/home/anil/$$ ./a.out
hello
hello
hello
hello
hello
hello
hello
hello.



note: the output may not be same all the times. Some times parent process ends first some times child process ends first.



Unix operating system Linux operating system shell programming bourn shell kourne shell c shell difference between unix and linux operating system , history of UNIX, red hat operating system. UNIX OS architecture , kernel utility programs , file handling process handling inter process communication pipes shared memory message queues socket programming TCP/IP , UDP programming , One to One chat Application , Basic shell program to add two numbers , echo function , while loops clear gt lt le ge ne eq if fi while do done case array in unix strings , cut copy paste cat dir pwd getcwd chdir command read write stat lseek fstat flock mechanism.even or add program vi editor command ni vi editor command mode esc mode insert mode aa dd x :q :wq :w. process tree process chain




No comments:

Post a Comment