ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 04 May 2017 My Price 8.00

program fork1.c in Programs folder

NOTE: For all answers, explain (concisely!) how you derived your answer. Diagrams are strongly encouraged where it makes sense.  Just providing the end-result gets NO credit.

 

 

Homework 1: See program fork1.c in Programs folder.

 

  • What is the value printed in LINE A. Explain why.
  • What is the value printed in LINE B. Explain why.
  • Run the program and validate your answers in 1) and 2). Provide a screenshot of your output.

 

Homework 2: See program fork2.c in Programs folder.

 

  • Including the initial process, how many processes are created. Explain why.
  • Update the program to print the identifiers of the processes created. Run the program and validate your answer in 1). Provide the updated source file and a screenshot that shows the program compiled correctly along with the program output.

Hint: Use getpid() system call.

 

programs attached

 

 

fork1.c

/*
* Homework 1
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int value = 10;
int main()
{
pid_t pid;
pid = fork();
if (pid == 0) { /* child process */
value += 15;
printf ("CHILD: value = %d\n",value); /* LINE A */
return 0;
}
else if (pid > 0) { /* parent process */
wait(NULL);
printf ("PARENT: value = %d\n",value); /* LINE B */
return 0;
}
return 0;
}

NOTE: For all answers, explain (concisely!) how you derived your answer. Diagrams are strongly encouraged where it makes sense.  Just providing the end-result gets NO credit.

 

 

Homework 1: See program fork1.c in Programs folder.

 

  • What is the value printed in LINE A. Explain why.
  • What is the value printed in LINE B. Explain why.
  • Run the program and validate your answers in 1) and 2). Provide a screenshot of your output.

 

Homework 2: See program fork2.c in Programs folder.

 

  • Including the initial process, how many processes are created. Explain why.
  • Update the program to print the identifiers of the processes created. Run the program and validate your answer in 1). Provide the updated source file and a screenshot that shows the program compiled correctly along with the program output.

Hint: Use getpid() system call.

 

programs attached

 

 

fork1.c

/*
* Homework 1
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int value = 10;
int main()
{
pid_t pid;
pid = fork();
if (pid == 0) { /* child process */
value += 15;
printf ("CHILD: value = %d\n",value); /* LINE A */
return 0;
}
else if (pid > 0) { /* parent process */
wait(NULL);
printf ("PARENT: value = %d\n",value); /* LINE B */
return 0;
}
return 0;
}

Answers

(11)
Status NEW Posted 04 May 2017 06:05 AM My Price 8.00

-----------

Not Rated(0)