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
You want to connect an external hard drive for backups. Which is the fastest connection used by current external hard drives
Fynjy0 [20]

Answer:

thunderbold proly

Explanation:

5 0
3 years ago
In addition to librarians, what other type of worker would you expect to find employed in a school or library
diamong [38]
In a school or library you can find a managor or boss

3 0
4 years ago
Read 2 more answers
How is a computer and a iphone different
MaRussiya [10]
A computer is a big screen and iphone is a handheld device
6 0
3 years ago
Which of the following scenarios describes an IT professional using the Internet and computer system access in an unprofessional
pantera1 [17]

Answer:

All of the above

Explanation:

6 0
3 years ago
Which of the following are benefits of designing a scalable system? Choose 3 options.
zhenek [66]

Which of the following are benefits of designing a scalable system? Choose 3 options.

  • ability to maintain a high level of service for customers ✔

system will never need to grow again

  • Ability to respond to user volume issues more quickly ✔
  • guaranteed system access for all users ✔

users may never know that a site has experienced tremendous growth

4 0
3 years ago
Other questions:
  • At which layer of the osi model is the entire message referred to as the payload
    15·1 answer
  • Someone please help fast! I’m taking the test rn and I don’t understand this!!!!!!
    15·1 answer
  • Where can you access email accounts on your Windows 7 computer in order to modify current account or create new ones
    15·1 answer
  • which of the following is something that an information systems (IS) professional would do? A. devise new ways to use computers
    10·1 answer
  • The following shared data structures must be declared as global variables such that they are shared by all threads
    7·1 answer
  • 20
    6·1 answer
  • What does c++ programming mean?
    7·1 answer
  • Explain the role that the number of data exchanges plays in the analysis of selection sort and bubble sort. What role, if any, d
    15·1 answer
  • I need help ASAP which option is an example of a resource that would most likely become a constraint in building a game
    7·2 answers
  • list three things that can spoil a printer if they are not of the correct specification and what damage may be caused​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!