Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

Swami Vivekananda Institute of Modern Science

Topic- Unix Process Life Cycle

Name- Bipul Raj


Roll No.- 26401220062
Reg No.- 202641001210006
Sem- 2nd
Year- 3rd
Subject Code- BCAC 601
Introduction to Unix Process Life
Cycle

 The Unix process life cycle refers to the stages a process goes through from creation to
termination in a Unix-based operating system.
 Understanding the process life cycle is important for system administrators and developers to
manage, schedule, execute, and terminate processes efficiently and effectively.
 The process life cycle determines how resources are utilized and affects the stability of the
system.
 Proper understanding of the process life cycle helps improve the performance of the system and
ensures its proper functioning.
Creating a new process in Unix
 System call ‘fork()’ is used to create a new process in Unix-like operating systems.
 ‘fork()’ duplicates the calling process, creating a child process that is a copy of the parent.
 The child process can then be differentiated from the parent process by checking the return value
of ‘fork()’.
 If ‘fork()’ returns 0 in the child process, it indicates that the child process has been successfully
created.
 The child process can then use the ‘exec()’ family of functions to replace the current process image
with a new process image.
 The parent process can wait for the child process to complete using the ‘wait()’ or ‘waitpid()’
system call.
 The child process can also exit using the ‘exit()’ function, which terminates the process and returns
a status code to the parent.
How process scheduler in Unix
works?
 The process scheduler maintains a list of all processes in the system, including both running and
waiting processes.
 The scheduler uses scheduling algorithms, such as Round Robin or Priority-based scheduling, to
determine the priority of each process.
 The process with the highest priority is selected and assigned to the CPU for execution.
 If a process is blocked waiting for I/O or other resources, the scheduler selects another process to
run.
 When the running process completes or yields the CPU voluntarily, the scheduler selects a new
process to run.
 The scheduler also takes into account the process priority and recent CPU usage to determine which
process should run next.
 This process continues in a loop, allowing the scheduler to dynamically adjust the allocation of
CPU time to processes based on their current state and priority.
Process Execution in
Unix
 A process is created using the ‘fork()’ system call, which creates a child process that is a copy of the
parent process.
 The child process can then use the ‘exec()’ family of functions to replace its current process image
with a new process image.
 The new process image starts executing the program code, with the entry point being the main
function of the program.
 The process may create additional child processes using ‘fork()’ or interact with the operating system
through system calls.
 The process may also allocate and deallocate resources, such as memory or file descriptors, as
needed.
 When the process completes its work, it can exit using the ‘exit()’ function.
 The parent process can use the ‘wait()’ or ‘waitpid()’ system call to wait for its child processes to
complete.
 The process scheduler allocates CPU time to the process and decides which process should run next
based on scheduling algorithms and the state of the processes.
 The process continues executing until it completes or is terminated by the operating system.
Process Termination in
Unix
 A process can terminate voluntarily by calling the ‘exit()’ function, which terminates the process and
returns a status code to the parent process.
 The parent process can use the ‘wait()’ or ‘waitpid()’ system call to wait for its child processes to
complete and retrieve the status code.
 A process can also be terminated by the operating system, such as in the case of a segmentation fault
or other error.
 The operating system generates a signal, such as SIGSEGV for a segmentation fault, which is
delivered to the process.
 The process can handle the signal using a signal handler, or it can ignore the signal.
 If the process does not handle the signal, the default action of the operating system is to terminate
the process.
 The operating system may also terminate the process if it violates a system resource constraint, such
as exceeding its memory limit.
What a zombie process is in
Unix?
 When a process terminates, it becomes a zombie process until its parent process calls ‘wait()’ or
‘waitpid()’ to retrieve its exit status.
 A zombie process retains its process ID and entry in the process table, but it no longer consumes
system resources such as memory or CPU time.
 Zombie processes can accumulate if their parent process fails to reap their status, leading to a
depletion of process IDs and potentially destabilizing the system.
 To prevent the accumulation of zombie processes, it is important for parent processes to regularly
call ‘wait()’ or ‘waitpid()’ to reap the status of their child processes.
 The ‘wait()’ and ‘waitpid()’ system calls allow the parent process to retrieve the exit status of its
child processes and remove them from the process table.
Process Suspension in Unix

 A process can be suspended by the operating system, such as in the case of a process priority
change or resource allocation.
 A process can also be suspended voluntarily by calling the ‘pause()’ function, which causes the
process to wait until it receives a signal.
 The process remains in a suspended state and does not consume CPU time until it is resumed.
 A suspended process can be resumed by the operating system, such as in the case of a process
priority change or resource allocation, or by the delivery of a signal to the process.
 Process suspension and resumption can be used for various purposes, such as managing process
priorities, resource allocation, and user-initiated process control.
Conclusion

 Summarize the different stages a process goes through in the Unix


environment
 Mention the importance of understanding the Unix process life cycle
 Highlight the benefits of understanding the Unix process life cycle for
system administrators and developers.
Thank You

You might also like