Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
  1. Use following code in C programming languages to create parent and child process and find the values? 



#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int value = 5;
int value2;
int main()
k
int pid;
L
pid = fork();
if (pid == 0)
]
{ /* child process */ value2 = value +15;
printf("CHILD process value = %d \n",value2 );
return 0;
}
else if (pid > 0)
{ /* parent process */ wait(NULL);
printf("PARENT process value = %d",value);
return 0;
}
]
C
expand button
Transcribed Image Text:#include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 5; int value2; int main() k int pid; L pid = fork(); if (pid == 0) ] { /* child process */ value2 = value +15; printf("CHILD process value = %d \n",value2 ); return 0; } else if (pid > 0) { /* parent process */ wait(NULL); printf("PARENT process value = %d",value); return 0; } ] C
Expert Solution
Check Mark
Step 1

The output of the program will be:

 

CHILD process value = 20

 

PARENT process value = 5

 

The child process will print "CHILD process value = 20" and the parent process will print "PARENT process value = 5".

 

 

Explanation:

The value of "value" will be passed down from the parent process to the child process in the form of the inherited value. After that, the value will be brought up to 20 by the child process by adding 15 to the value that it inherited. Before publishing the value of "value," the parent process will wait for the child process to finish and then return to its own state. In the parent process, the value of the variable "value" will not change; it will continue to be 5. a process that enables one item to take on the characteristics and act in the same way as another object. When discussing fork() and exec(), the term "inheritance" refers to the phenomenon in which the characteristics of the parent process are passed down to the child process. 

This includes the values of any variables that are defined in the process that is being referred to as the parent. Using the fork() system function will result in the beginning of a new process. The new procedure is essentially an identical replica of the previous procedure. The newer process is considered to be the kid process, while the older process is considered to be the parent process. The characteristics of the parent process are passed down to the child process during the process of inheritance. This includes the values of any variables that are defined in the process that is being referred to as the parent.

Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY