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]
3 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]3 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
Is there any way to delete old questions on this? if there is no way, take this as a free question​
Lostsunrise [7]

Answer:

moderators have to delete it for u

Explanation:

8 0
3 years ago
Read 2 more answers
A (n) _____, similar to a trojan horse, installs monitoring software in addition to the regular software that a user downloads o
galina1969 [7]

Answer:

Spyware

Explanation:

Internet is a type of computer network that allow device communicate with each other world wide. So, it is not the correct option.

Worm: this is a standalone malware computer program that replicates itself in order to spread to other computers. It spreads copies of itself from computer to computer. A worm can replicate itself without any human interaction, and it does not need to attach itself to a software program in order to cause damage. The major feature of a worm is ability to replicate on it own. So, it is not the correct option.

Bot: this is a software application that runs automated tasks. So, it is not the correct option.

Middleware: this is software that lies between an operating system and the applications running on it, enabling communication and data management. It provides services to software applications beyond those available from the operating system. So, it is not the correct option.

Spyware: this is the correct answer. Spyware is similar to trojan horse because it hides itself in a system and a user may not know that it exist on the system. Spyware is a form of malware that hides on your device, monitors your activity, and steals sensitive information without knowledge of the user.

5 0
3 years ago
Read 2 more answers
Write a program that asks length and breadth of a rectangle a calculate its area qbasic​
Natasha_Volkova [10]

Answer:

INPUT "Enter the length";l

INPUT "Enter the width";w

PRINT "The area is ";l*w

5 0
3 years ago
An i/o system call returns a one-bit information about the status of the call.
amid [387]

An i/o system call returns one-bit information about the call's status, Therefore the given statement is true.

<h3>What is an i/o system?</h3>
  • I/O (Input/Output) is a type of data processing system that sends and receives data from a computer hardware component, device, or network. A network allows data to be sent between devices. Computers would be unable to communicate with other systems or devices if I/O was not present.
  • The primary function of an i/o system is processor communication, which includes a variety of tasks such as data transfer between the processor and an I/O module, accepting and decoding commands sent by the processor, reporting current status, and the ability for the I/O module to recognize its own unique address.
  • A system call allows a user program to communicate with the operating system. The program requests a number of services, and the operating system responds by invoking a series of system calls to fulfill the request.

To learn more about i/o system call  refer to :

brainly.com/question/1763761

#SPJ4

6 0
1 year ago
What is the definition of a nested function?
ExtremeBDS [4]

Answer:

A function that is defined within another function.

6 0
3 years ago
Other questions:
  • Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompt
    9·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    12·1 answer
  • If an engine has four cylinders and a total of 16 valves, how many valves would each cylinder have? A. Two B. One C. Four D. Thr
    12·1 answer
  • Which of the following is the correct ordering of operating systems, oldest to newest?
    5·2 answers
  • US-CERT is a set of moderated mailing lists full of detailed, full-disclosure discussions and announcements about computer secur
    15·1 answer
  • Write a Python program string_functions.py that defines several functions. Each function re-implements Python's built-in string
    9·1 answer
  • The working window of a presentation is the O outline O handout 0 notes o slide​
    5·2 answers
  • Explain how you think robotics plays a part in the subway driver's job.
    13·2 answers
  • Capstone Project part 11 quiz
    6·1 answer
  • X = 9 % 2if (x == 1):  print ("ONE")else:  print ("TWO")
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!