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
Tanya [424]
3 years ago
11

Using the program below, explain what the output will be at LINE A. 1 #include 2#include 3#include 4 5 int value - 128; 6 7 int

main 8 9 pid.t pid; 10 11 pid=fork 12 13 if (pid 0) { /* child process */ 14 15 16 value +8; return 0; 17 else if (pid > 0) parent process / 18 19 20 21 wait (NULL); printf ("PARENT: return 0; value =%d\n" ,value); /* LINEA */
Computers and Technology
1 answer:
slega [8]3 years ago
5 0

Answer:

This is the complete correct program:

#include <stdio.h>

#include<sys/types.h>

#include<unistd.h>

int value = 128;

int main()

{

  pid_t pid;

  pid=fork();

  if (pid==0) /* child process */

  {

  value +=8;

  return 0; }

  else if (pid > 0) {/* parent process */

 wait (NULL);

 printf ("PARENT: value =%d\n" ,value); /* LINEA */

 return 0;

}

}

The output of the LINE A is:

PARENT: value = 128

Explanation:

The fork() function used in the program creates a new process and this process is the child process. The child process is same as the original process having its own address space or memory.

In the child process the value of pid is 0. So the if condition checks if pid==0. Then the child process adds 8 to the value of its variable according to the following statement  

value +=8;

Now the original process has value = 128. In else if part the parents process has the value of pid greater than zero and this portion of the program is of the parent process :

else if (pid > 0)

{ wait (NULL);

printf ("PARENT: value =%d\n" ,value);

return 0; }

So the value 128 is printed at the end in the output.

wait(NULL) is used to wait for the child process to terminate so the parent process waits untill child process completes.

So the conclusion is that even if the value of the variable pid is changed in the child process but it will not affect the value in the variable of the parent process.

You might be interested in
I get brainlist to whoever can help my computer is doing this and I have class and it’s not working and I got it wet yesterday b
liq [111]

Answer:

try putting a lot of rice on the screen.

Explanation:

if it got water in it that should help it.

3 0
2 years ago
Read 2 more answers
Which actions did Sheila have to take to make the changes observed? Check all that apply.
Harrizon [31]

Answer:

Use

Explanation:

Out line view

6 0
3 years ago
Hjnjjjhhbbfg66ui998876dch
GalinKa [24]
What is your question? I’ll try my best to help
4 0
3 years ago
What is star topology
Alexxx [7]
Every node connects to a central network device. like a hub, switch, or computer.
4 0
3 years ago
Read 2 more answers
Select the six criteria for a baseline.
Karo-lina-s [1.5K]

Explanation:

nose pero también se usa para la musica electronica

6 0
3 years ago
Other questions:
  • What is used for World Wide Web?
    7·1 answer
  • Write a Python program to do the following: (a)Use a for loop and a random integer generator to generate 5 random integers in 1
    10·1 answer
  • A network protocol is a set of rules defining communication between two devices. True False
    8·2 answers
  • Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A
    5·1 answer
  • First write a method to calculate the greatest common divisor (GCD) of two positive integers using Euclid’s algorithm (also know
    10·1 answer
  • How can the function anotherFunc2 change the contents of the second element of t?
    5·1 answer
  • Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a
    14·1 answer
  • What is a benefit of the rise in citizen journalism? Multiple answer choice below
    13·1 answer
  • The process of combining rows and columns in a table is called _____.
    8·1 answer
  • a term to describe article that can be displayed in their entirety as opposed to abstract and reference only?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!