Write a program that shows the distinction between child and parent process? - CGI Programming
Write a program that shows the distinction between child and parent process?
- Child process allows the execution of the program if it returns the zero value from the fork.
- It executes the command till the time parent waits for the process to get completed.
- The implementation of the server can be done to handle the multiple connections and it is as follows:
$SIG{'CHLD'} = "wait_for_child_to_die";
while (1) {
( ($ip_name, $ip_address) = &accept_connection (COOKIE, SOCKET) )
|| die "Could not accept connection.", "\n";
if (fork) {
# Parent Process (do almost nothing here)
} else {
# Child Process (do almost everything here)
}
&close_connection (COOKIE);
}
sub wait_for_child_to_die
{
wait;
}
- The zombie process can be created if the parent process doesn’t wait for the child process to die.