1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ipatiy [6.2K]
4 years ago
5

Write a program that calls fork(). Before calling fork(), have the main process access a variable (e.g., x) and set its value to

some-thing (e.g., 100). What value is the variable in the child process? What happens to the variable when both the child and parent change the value of x? Write out the code to your program. Run the program and show your result. What value is the variable in the child process? What happens to the variable when both the child and parent change the value of x?

Computers and Technology
1 answer:
vesna_86 [32]4 years ago
7 0

Answer:

Here is the program:

#include <stdio.h>  //to use input output functions

#include <unistd.h> //provides access to the POSIX OS API

int main() { //start of main function

   int x;  //declare an int type variable x

   x = 100;  // sets the value of x to 100

   int r = fork();  //calls fork() method to create a new process. r is used to store the value returned by fork()

   if(r<0){  //if fork() returns -1 this means no child process is created

           fprintf(stderr, "Error");}     //prints the error message using standard error stream

  else if (r == 0)     {  //if fork returns 0 this means child process is created

       printf("This is child process\n");  //prints this message

       x = 150;  //changes value of x to 150

       printf("Value of x in child process: %d\n", x);     }  //prints the new value of x in child process

   else      {

       printf("This is parent process\n");  //if r>0

       x = 200;  //changes value of x to 200

       printf("Value of x in parent process: %d\n", x);     }  } //prints the new value of x in parent process

Explanation:

The program is well explained in the comments added to each line of the code. The answers to the rest of the questions are as follows:

What value is the variable in the child process?

The variable x is set to 150 in child process. So the printf() statement displays 150 on the screen.

What happens to the variable when both the child and parent change the value of x?

fork() creates a copy of parent process. The child and parent processes have their own private address space. Therefore none of the both processes cannot interfere in each other's memory. The both maintain their own copy of variables. So, when parent process prints the value 200 and child process prints the value 150.

In order to see which is the final value of x, lets write a statement outside all of the if else statements:

  printf("Final value of x: %d\n", x);

This line is displayed after the value of parent class i.e. 200 is printed on the screen and it shows:

Final value of x: 200

Note this is the value of x in parent process

However the same line displayed after the value of child class i.e. 150 is printed on the screen and it shows:

Final value of x: 150

The screenshot of the program along with the output is attached.

You might be interested in
The term platform as a service has generally meant a package of security services offered by a service provider that offloads mu
Stells [14]

Answer:false

Explanation:

8 0
3 years ago
A technician has been told that a keyboard is not responding at all. What can the technician do quickly to determine whether tha
givi [52]

Answer:

Press Caps Lock key to see the light illuminates or not

Explanation:

Computer keyboard is the typewriter-style device that uses arrangement of the buttons or the keys to act as the mechanical levers or the electronic switches.

Keyboard keys  have characters which are engraved or printed on the surface and press of each key corresponds to the single written symbol.

If the keyboard is not working and to see whether it is working or not, there is a Caps Lock key on the keyboard. Generally, all keyboards have a Caps Lock light which will light up if the button is on. So, this can be a quick check.

6 0
4 years ago
Add an array, which will store the most recent 5 recent transactions. For the array, add an insert function which will store the
Vika [28.1K]

The answer & explanation for this question is given in the attachment below.

Download docx
4 0
3 years ago
________ is a mobile broadband technology that relies on microwave transmissions to blanket large metropolitan areas from microw
FinnZ [79.3K]

Answer:

WiMax

Explanation:

Wimax is a family standards of a communication of bandwidth, this is a standard IEEE 802.16, was created to provide data velocity like 30 or 40 megabits per seconds, but in 2011 was updated, and now can provide 1 gigabit per second, the name WiMAX is for a forum created in 2001 to promote the standard.

4 0
3 years ago
How would you like your social media profiles/personas to be treated in the event of your death? why?
White raven [17]
Depends on the person really. personally i would like it all to be kept for memories but never used anymore
7 0
3 years ago
Read 2 more answers
Other questions:
  • Side mirror using convex mirror or concave mirror?​
    5·2 answers
  • Which of the following statements will assign the contents of the Text property of a Textbox control named txtInput into the Tex
    10·1 answer
  • What can help prevent issues related to downloading content from the internet
    11·2 answers
  • Which ieee 802.11 standard provides for throughput of up to 7 gbps?
    8·1 answer
  • The code segment below is intended to randomly print one of the values 2, 4, 6, or 8 with equal probability.
    12·1 answer
  • Write the C++ if statement that compares the contents of the quanity variable to the number 10. If the quantity variable contain
    12·1 answer
  • Colin Mackay Inc., a software company with its head office in Amsterdam, has employees across three continents. Certain project
    11·1 answer
  • Advantages of a grain crush​
    9·1 answer
  • Who is the founder of C language?​
    9·1 answer
  • A designer wraps up a final prototype of a language learning app in Adobe XD, and wants to share their work with the development
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!