Course 102: Lecture 18: Process Life Cycle
-
Upload
ahmed-el-arabawy -
Category
Technology
-
view
45 -
download
2
Transcript of Course 102: Lecture 18: Process Life Cycle
![Page 1: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/1.jpg)
Linux For Embedded Systems For Arabs
Ahmed ElArabawy
Course 102: Understanding Linux
![Page 2: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/2.jpg)
Lecture 18: Process Life-Cycle
![Page 3: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/3.jpg)
PROCESS CREATION
![Page 4: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/4.jpg)
Fork-Exec Procedure
• Creating a new process happens in two steps
• Fork:
In this step the new process (child process) is created and inherits its features from its parent
• Execute:
In this step the new process (child process) separates from its parent and move on with its functionality
![Page 5: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/5.jpg)
Fork Execute
![Page 6: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/6.jpg)
Fork
• The Job of “Fork” in is to create a new process (child process) and prepare it with what it needs to be able to run….
• This includes, • Assign it a new pid
• Creates associated Structures in the Kernel
• Sets the ppid, pgid, sid, and any other attributes
• Add it to the Kernel scheduler queue to give it time slots to run
• Copy parent memory space (all memory associated with the parent process) to the child process memory space
• Copy Other parent process resources, • Normal file handlers
• Socket handlers
• Shared memory handlers
• ….
![Page 7: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/7.jpg)
Exec
• The job of “Exec” is to send the child process on its own to do its assigned job
• This means the child process will be loaded with,
• New memory space instead of its parent
• Will lose access to parent process resources
• A pointer to the new program to run
• This command separates the child process from its parent, and the child process runs now on its own, using its own memory address space, and running its own executable and creating/reserving its own system resources
![Page 8: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/8.jpg)
Process
Address Space
Process Creation: Parent Process
![Page 9: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/9.jpg)
Process
Address Space
Child Process
Fork
Process Creation: Fork Procedure
![Page 10: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/10.jpg)
Process
Address Space
Child Process
Fork
COPY Copied Address Space
Process Creation: Copying Address Space
![Page 11: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/11.jpg)
Process Creation: Exec Procedure
Process
Address Space
Child Process
Exec
New Address Space
![Page 12: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/12.jpg)
Process Creation: Parent and Child Processes
Process
Address Space
Child Process
New Address Space
![Page 13: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/13.jpg)
Process Vs. Thread
![Page 14: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/14.jpg)
Process Vs. Thread
• Both processes and threads are threads of execution that enable parallel operation (multi-tasking) with the help of the scheduler in the kernel
• In both cases, the Linux kernel assigns time slots for the process/thread to execute before another one is assigned
• In Linux a thread is a process with some special differences:
• When creating a thread, the address space (and some other resources) are not copied from the parent. They are shared with the parent
• This means threads run within the same address space of its parent and never get a new address space
• Other than that, threads are treated exactly the same as processes • For example the kernel scheduler deals with each thread
independently
• So, threads created by the same process are multiple processes that share the same address space and resources of their parent process
![Page 15: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/15.jpg)
Creating a Thread: Parent Process
Process
Address Space
![Page 16: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/16.jpg)
Creating a Thread: Fork Procedure
Process
Address Space
Child Process
Fork
![Page 17: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/17.jpg)
Process Termination
![Page 18: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/18.jpg)
Process Termination
• A process is terminated by • Normal termination (reaching the end of its operation)
• Receiving a Signal that cause it to terminate itself
• Terminated by the kernel
• When the process is terminated, some of its resources are not yet released, and it changes its state to the Zombie state.
• The parent process must be waiting for its children processes to perform the required cleanup of resources
• Once the parent process perform the required cleanup, the process state is no longer in Zombie
• This is why every process must have a living parent, and if its parent process terminates, the child processes are re-parented to the init process
![Page 19: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/19.jpg)
Process States
![Page 20: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/20.jpg)
Running
![Page 21: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/21.jpg)
Stopped
![Page 22: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/22.jpg)
Waiting for some Event
![Page 23: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/23.jpg)
Zombie
![Page 24: Course 102: Lecture 18: Process Life Cycle](https://reader034.fdocuments.in/reader034/viewer/2022042701/55ceb3bcbb61eb3f1e8b479b/html5/thumbnails/24.jpg)
Process States