Question

Discuss your understanding using an example: How to create a child process using fork, running a...

Discuss your understanding using an example:

  • How to create a child process using fork, running a C function using the child process, and parent process learning using the waitpid function to conclude that the child process has completed. This will help you with A07.
  • Discuss your understanding of the Example in Figure 11.2 and capture a screenshot of your results of running that code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

#include <sys/wait.h>

#include <unistd.h>

int main() {

  pid_t processId = fork();

  // parent process fork() > 0

  if (processId > 0) {

    wait(NULL);

printf("\nParent Process is being Terminated");

  }

  

// child process fork() == 0

  else if (processId == 0) {

    sleep(3);

    wait(NULL);

    printf("\nChild Process is being Terminated");

  }

  return 0;

}

clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)

Child Process is being Terminated
Parent Process is being Terminated

Add a comment
Know the answer?
Add Answer to:
Discuss your understanding using an example: How to create a child process using fork, running a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT