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
icon
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
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
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
ADT and Class
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education