logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

We can use the fork() system call to create a new process (referred to as the child process) which is an identical image of the calling process

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Objectives 

The objective of this lab is to introduce you to create processes and manage them. 

1. Creating child processes using fork. 

2. Replacing child process using exec. 

Description  

Example 1: 

We can use the fork() system call to create a new process (referred to as the child process) which is an identical image of the calling process (referred to as the parent process). Here is the C interface for the fork() system call: 

#include <unistd.h>

 

pid_t fork(void); 

If the fork() call is successful, then it returns the process ID of the child process to the parent process and returns 0 in the child process. fork() returns a negative value in the parent process and sets the corresponding errno variable (external variable defined in errno.h) if there is any error in process creation and the child process is not created. We can use perror() function (defined in stdio.h) to print the corresponding system error message. Look at the man page for perror to find out more about the perror() function. 

Once the parent process creates the child process, the parent process continues with its normal execution. If the parent process exits before the child process completes its execution and terminates, the child process will become a zombie process (i.e., a process without a parent process). Alternatively, the parent process could wait for the child process to terminate using the wait() function. The wait() system call will suspend the execution of the calling process until one of the child process terminates and if there are no child processes available the wait() function returns immediately. The wait() call returns the PID of the child process that terminated when successful, otherwise, it returns -1. The wait() call also sets an integer value that is passed as an argument to the function which can be inspected with various macros provided in <sys/wait.h> to determine how the child process completed (e.g., terminated normally, terminated by a signal). 

If the calling process created more than one child process, we can use the waitpid() system call to wait on a specific child process to change state. A state change could be any one of the following events: the child was terminated; the child was stopped by a signal; or the child was resumed by a signal. Similar to wait(), waitpid() returns the PID of the child process that changed state when successful, otherwise, it returns -1. 

Here are the C APIs for the wait() and waitpid() system calls: 

 

(5/5)
Attachments:

Expert's Answer

568 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

568 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

584 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

543 Answers

Hire Me
expert
Husnain SaeedComputer science

811 Answers

Hire Me
expert
Atharva PatilComputer science

724 Answers

Hire Me