processes OUTLINE Process Concept Process Scheduling Operations on Processes Inter-process Communication Examples of IPC Systems Communication in Client-Server Systems
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Process creation A process may create several processes during the execution. Creating process is called a parent and a created process is called a child . Parent process create children process, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier ( pid )
Process creation: fork() Creates a child process. Child process contains exact copy of the memory space of the parent process. Child process contains the same text/code section but executes independently
Exec() Exec is a collection of function e.g., execlp () , ececve () , execl () , are use to execute any program/script. Typically exec used after a fork() by child process to replace the memory space with a new program. PID does not change but the data, heap, and stack of the child are replace by new program
Process creation (cont..) Fork( ) system call creates new process Exec( ) system call used after fork to replace the process memory space with a new program.
Process Termination Process executes last statement and asks the operating system to delete it (exit) Process resources are deallocated by operating system Parent may terminate execution of children processes (abort). Task assigned to child is no longer required If parent is exiting Some operating system do not allow to continue if its parent terminates All children terminated – cascading termination.
15 Execution Trace: fork() RAM CPU Kernel stack data text …. n=fork(); If (n == 0) .. else if (n>0) ... PC PCB-Parent Process-Parent x pid PC n sys_fork() {….} PC y pid PCB-Child text Process-Child n stack data …. n=fork(); If (n == 0) .. else if (n>0) ... y
16 Execution Trace: fork() with execlp() RAM CPU Kernel stack data text …. n=fork(); If (n == 0) …exec() else if (n>0) ... PC PCB-Parent Process-Parent x pid PC n sys_fork() {….} PC y pid PCB-Child text Process-Child n stack data …. n=fork(); If (n == 0) …exec() else if (n>0) ... y sys_execve() {….} new code