Question: using linux ubuntu clone Q2. Inheriting environment variables from parents In this task, we study how environment variables are inherited by child processes from their

using linux ubuntu clone
using linux ubuntu clone Q2. Inheriting environment variables from parents In this

Q2. Inheriting environment variables from parents In this task, we study how environment variables are inherited by child processes from their parents. 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. In this task, we would like to know whether the parent's environment variables are inherited by the child process or not. Step 1. Please compile and run the following program, and describe your observation. Because the output contains many strings, you should save the output into a file, such as using child (assuming that a.out is your executable file name). a.out> #include #include #include extern char environ; void printend) (int is 0; while (environ[i] != NULL) printf("%s ", environ(0); i++; 1 > void main() pid_t childPid; switch(childPid = fork()) { case 0: /* child process printenv(); exit(0); default: /* parent process */ // printenv(); exit(0); } > Step 2. Now comment out the printenv() statement in the child process case, and uncomment the printenv() statement in the parent process case. Compile and run the code, and describe your observation. Save the output in another file. Step 3. Compare the difference of these two files using the diff command. Please draw your conclusion

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!