Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
expand button
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.
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education