Use following code in C programming languages to create parent and child process and find the values?
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
Process by which instructions are given to a computer, software program, or application using code.
Expert Solution
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.