PROCESS CREATION o Parent process create children processes,which, in turn create other processes,forming a tree of processes o Resource sharing Parent and children share all resources Children share subset of parent's resources Parent and child share no resources o Execution Parent and children execute concurrently Parent waits until children terminate
PROCESS CREATION Parent process create children processes, which, in turn create other processes, forming a tree of processes Resource sharing Parent and children share all resources Children share subset of parent’s resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until children terminate
A TREE OF PROCESSES ON A TYPICAL SOLARIS Sched pid 0 init pageout fsflush pid =1 pid =2 pid =3 inetd dtlogin pid =140 pid 251 telnetdaemon Xsession pid=7776 pid 294 Csh sdt shel pid=7778 pid =340 Csh pid=1400 Netscape emacs pid=7785 pid=8105 Is cat pid=2123 pid=2536
A TREE OF PROCESSES ON A TYPICAL SOLARIS
PROCESS CREATION (CONT.) o Address space Child duplicate of parent Child has a program loaded into it o UNIX examples fork system call creates new process exec system call used after a fork to replace the process'memory space with a new program
PROCESS CREATION (CONT.) Address space Child duplicate of parent Child has a program loaded into it UNIX examples fork system call creates new process exec system call used after a fork to replace the process’ memory space with a new program
PROCESS CREATION parent resumes wait fork() child exec() exit()
PROCESS CREATION
PROCESS CREATION IN POSIX #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main() pid_t pid; /fork a child process * pid fork(); if (pid 0){/*error occurred * fprintf(stderr,"Fork Failed"); exit(-1); else if (pid ==0){/*child process * execlp("/bin/1s","1s",NULL); else{/*parent process * /parent will vait for the child to complete * wait(NULL); printf("Child Complete"); exit(0);
PROCESS CREATION IN POSIX