The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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.
Â
Â
Homework 2: See program fork2.c in Programs folder.
Â
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.
Â
Â
Homework 2: See program fork2.c in Programs folder.
Â
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;
}