Modify the C program shown in Example 1 in Lecture Note 2 such that the new program will generate one parent process and three child processes (which all of them created by the parent process). The output of this program will show each child process PID and its parent process ID. For example, A child process with PID: 1001 (parent process PID: 1000). A child process with PID: 1002 (parent process PID: 1000). A child process with PID: 1003 (parent process PID: 1000). Because all of them have the same parent process, their parent process PID is the same. 2.1) Take a screenshot of your program and put here.
Modify the C program shown in Example 1 in Lecture Note 2 such that the new program will generate one parent process and three child processes (which all of them created by the parent process). The output of this program will show each child process PID and its parent process ID. For example, A child process with PID: 1001 (parent process PID: 1000). A child process with PID: 1002 (parent process PID: 1000). A child process with PID: 1003 (parent process PID: 1000). Because all of them have the same parent process, their parent process PID is the same. 2.1) Take a screenshot of your program and put here.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![Example 1: Parent and Child Processes
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
At this point, create a
child process. Now we
have two processes (two
copies of this C program
are running concurrently):
Parent process (rc > 0)
Child process (rc = 0)
starts from here.
Terminate according
to an error.
Wait until the child process
terminates.
int main(int argc, char
{
}
This C program is saved as Process.c.
This C program is available in the
Google Classroom.
*argv[])
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) {
// fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) {
To get the PID
// child (new process)
printf("hello, I am child (pid:%d)\n", (int) getpid());
}
return 0;
} else {
// parent goes down this path (original process)
watt(NULL);
printf("hello, I am parent of %d (pid:%d)\n",
rc, (int) getpid());
33](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2b9173c6-d6b4-4ba9-960a-2b5f7be4d351%2F02fa388b-824c-4048-b8bd-f669fa1b2eff%2Fnhds3o_processed.jpeg&w=3840&q=75)
Transcribed Image Text:Example 1: Parent and Child Processes
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
At this point, create a
child process. Now we
have two processes (two
copies of this C program
are running concurrently):
Parent process (rc > 0)
Child process (rc = 0)
starts from here.
Terminate according
to an error.
Wait until the child process
terminates.
int main(int argc, char
{
}
This C program is saved as Process.c.
This C program is available in the
Google Classroom.
*argv[])
printf("hello world (pid:%d)\n", (int) getpid());
int rc = fork();
if (rc < 0) {
// fork failed; exit
fprintf(stderr, "fork failed\n");
exit(1);
} else if (rc == 0) {
To get the PID
// child (new process)
printf("hello, I am child (pid:%d)\n", (int) getpid());
}
return 0;
} else {
// parent goes down this path (original process)
watt(NULL);
printf("hello, I am parent of %d (pid:%d)\n",
rc, (int) getpid());
33

Transcribed Image Text:2. Modify the C program shown in Example 1 in Lecture Note 2 such that the new program will
generate one parent process and three child processes (which all of them created by the parent
process). The output of this program will show each child process PID and its parent process ID.
For example,
A child process with PID: 1001 (parent process PID: 1000).
A child process with PID: 1002 (parent process PID: 1000).
A child process with PID: 1003 (parent process PID: 1000).
Because all of them have the same parent process, their parent process PID is the same.
2.1) Take a screenshot of your program and put here.
2.2) Compile and run your program. Take a screenshot of your program's output and put here.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education