Download presentation
Presentation is loading. Please wait.
1
Process Creation Process Termination
Process Management Process Creation Process Termination Textbook Silberschatz,6th ed. Chapter 4
2
Process Tree
3
-- soft or hard request to terminate the process
4
Unix Fork/Exec/Exit/Wait Example
parent int pid = fork(); Create a new process that is a clone of its parent. exec*(“program” [, argvp, envp]); Overlay the calling process virtual memory with a new program, and transfer control to it. exit(status); Exit with status, destroying the process. int pid = wait*(&status); Wait for exit (or other status change) of a child. fork parent fork child initialize child context exec wait exit
5
Process Creation, Fork()
6
Fork(). More Explanation
2. var= or var=0 2. var=0 2. var=101
8
Blocking, Non Blocking fork()
#include <stdio.h> int main(int argc, char *argv [] ) { int var; var = fork(); /* fork another process */ if (var < 0) { /* error occurred */ fprintf (stderr , "Fork Failed") ; exit (-1) ; } else if (var == 0) { /* child process */ execlp("/bin/ls" , "ls" ,NULL) ; else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL) ; printf ("Child Complete") ; exit (0) ; The parent continues to execute concurrently with its children. The parent waits until some or all of its children have terminated. Do other tasks in parent process. wait (NULL); waitpid (PID);
9
Address space overload
#include <stdio.h> int main(int argc, char *argv [] ) { int var; var = fork(); /* fork another process */ if (var < 0) { /* error occurred */ fprintf (stderr , "Fork Failed") ; exit (-1) ; } else if (var == 0) { /* child process */ execlp("/bin/ls" , "ls" ,NULL); execlp("/bin/ps" , “ps" ,NULL); else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL) ; printf ("Child Complete") ; exit (0) ; The child process is a duplicate of the parent process. The child process has a program loaded into it. What will be the effect of the second execlp ?
10
Process Termination The process completed its operation
All the resources of the process including physical and virtual memory open files I/O buffers are deallocated by the operating system.
11
Process Termination OS The process exceeded its limit of some resource
printf ("I’m Child") ; printf (“I need more stack"); . . . exit (0) ; /* parent waiting for the child to complete */ wait (NULL) ; printf ("Child Complete") ; exit (0) ; OS No more stack for you. Terminating... Informing the parent... All the resources of the process: including physical and virtual memory open files I/O buffers are deallocated by the operating system.
12
Process Termination soft or hard request to terminate the process
A process can cause the termination of another process via an appropriate system call (for example, kill). Signal 15 – Soft Termination The target process should accept this signal and self terminated Signal 9 – Hard Termination (Kill) The target process is killed arbitrarily The process sending the kill signal should have the appropriate permission to kill the target
13
Process Termination Parent is exited or killed
The operating system does not allow a child to continue if its parent terminates. On such systems, if a process terminates (either normally or abnormally), then all its children must also be terminated. This phenomenon, referred to as cascading termination, is normally initiated by the operating system. The Parent terminates all its children trees before it terminates itself by special “kill” signals Otherwise the child processes will become orphans and will get as the parent PID the init process ID or be killed or become Zombies without parent PID.
14
What does it take to create a process?
Must construct new PCB Inexpensive Must set up new page tables for address space More expensive (find free spaces and create tables) Copy data from parent process? (Unix fork() ) Semantics of Unix fork() are that the child process gets a complete copy of the parent memory and I/O state Originally very expensive Much less expensive with “copy on write” The “copy on write” makes private copies of the shared pages only if the child wants to make changes.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.