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]
2 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]2 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
Consider the following class definitions.
Serggg [28]

Answer:

The correct answer is option A

Explanation:

Solution

Recall that:

From the question stated,the following segments of code that should be used in replacing the /* missing code */ so that the value 20 will be printed is given below:

Android a = new Android(x);

a.setServoCount(y);

System.out.println(a.getServoCount());

The right option to be used here is A.

4 0
3 years ago
What standards organization maintains the ethernet standard?.
Fofino [41]

Answer:

Ethernet standards are written and maintained by the IEEE, the Institute of Electrical and Electronic Engineers which has its corporate office in New York City and its operations center in Piscataway, New Jersey.

Explanation:

5 0
2 years ago
Write a subclass named 'ReadWrite' with the following additional behavior: Any necessary constructors. a method named 'setVal' t
nataly862011 [7]

Answer:

Java Class given below

Explanation:

class ReadOnly

{

protected int val;

public ReadOnly(int arg)

{

val = arg;

}

public int getVal()

{

return val;

}

}

class ReadWrite extends ReadOnly

{

private boolean dirty;

public ReadWrite(int arg)

{

super(arg);

dirty = false;

}

public void setVal(int arg)

{

val = arg;

dirty = true;

}

public boolean isDirty()

{

return dirty;

}

}

6 0
3 years ago
Qué propiedades del bromato de potasio han hecho que sea el aditivo más usado en la fabricación del pan​
torisob [31]

Answer:

es la capacidad de unir proteínas presentes en la harina

4 0
3 years ago
Data with values that change continuously or smoothly over time is known as:
Alexeev081 [22]

Answer:

A.  \:  \boxed{analog  \: data}

5 0
3 years ago
Read 2 more answers
Other questions:
  • Search the internet for news of a motor vehicle collision in your community involving drugs or alcohol. Keeping in mind that you
    15·1 answer
  • HTTP is made to facilitate which kind of communication?
    11·1 answer
  • A device receives a Transmission Control Protocol (TCP) packet. The device understands where the actual data payload begins. Whi
    15·1 answer
  • What component of Kerberos is responsible for storing keys for encrypting and decrypting data in the authentication process?
    13·1 answer
  • We have a 16 GB main memory and 256 MB fully-associative cache, with block size of 64 bytes. We wish to store a 6 x 6 matrix in
    5·1 answer
  • A network administrator is configuring the triggering mechanism for the network-based IPS by defining a pattern of web surfing a
    10·2 answers
  • By default the normal style inserts a vertical space equal to _____ lines between each line of text
    9·1 answer
  • All states that have altered judicial selection techniques in recent years have adopted some form of:
    10·2 answers
  • Write function d2x() that takes as input a nonnegative integer n (in the standard decimal representation) and an integer x betwe
    14·1 answer
  • Write a function DrivingCost with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar co
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!