Question: In this task, we study how a child process gets its environment variables from its parent. In Unix, fork ( ) creates a new process
In this task, we study how a child process gets its environment variables from its parent. In Unix, fork
creates a new process by duplicating the calling process. The new process, referred to as the child, is an
exact duplicate of the calling process, referred to as the parent; however, several things are not inherited by
the child please see the manual of fork by typing the following command: man fork In this task,
we would like to know whether the parents environment variables are inherited by the child process or not.
Step Please compile and run the following program, and describe your observation. The program can
be found in the Labsetupfolder; it can be compiled using gcc myprintenv.c whichwillgenerate
a binary called aout. Lets run it and save the output into a file using aout file".
Listing : myprintenv.c
#include
#include
#include
extern char environ;
void printenv
int i ;
while environi NULL
printfs
environi;
i;
void main
pidt childPid;
switchchildPid fork
case : child process
printenv;
exit;
default: parent process
printenv
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
