Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CAN YOU CREATE THIS USING C CODE. SAMPLE RESULT SHOULD BE LIKE THE ONE POSTED. Objective: To simulate process creation and destruction when implemented with

image text in transcribedimage text in transcribedimage text in transcribed

CAN YOU CREATE THIS USING C CODE. SAMPLE RESULT SHOULD BE LIKE THE ONE POSTED.

Objective: To simulate process creation and destruction when implemented with linked lists. Specification: The program creates/destroys child processes based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are: 1) Initialize process hierarchy 2) Create a new child process 3) Destroy all descendants of a parent process 4) Quit program and free memory Assignment: - Create a process creation hierarchy as an array of length MAX_PROCESSES which references process control blocks (PCBs), indexed 0 to MAX_PROCESSES-1. - Each PCB is a structure consisting of two fields: parent: a PCB index corresponding to the process' creator children: a pointer to a linked list, where each node contains the PCB index of one child process and a link to the next child in the linked list - The necessary functions are simplified as follows: - create_child( represents the create function, which prompts for the parent process p. The function creates a new child process q of process p by performing the following tasks: allocate memory for an unused PCB[q] - record the parent's index, p, in PCB[q] - initialize the list of children of PCB[q] as empty (NULL) - create a new link containing the child's index q and append the link to the children field of PCB[p] destroy_descendants() represents the destroy function, which prompts for the parent process p. The function recursively destroys all descendent processes (child, grandchild, etc.) of process p by performing the following tasks: for each element q on the linked list of children of p : - destroy_desecndants(q) (recursively destroy all descendants of q ) - free memory utilized by PCB[q] and set it to NULL - Free memory utilized by the node with id q and set it to NULL Process creation and destruction 1) Initialize process hierarchy 2) Create a new child process 3) Destroy all descendants of a process 4) Quit program and tree memory Enter selection: 1 Frocess 11st: Process id: 0 Parent process: a Process creation and destruction 1) Initialize process hierarchy 2) Create a new child process 3) Destroy all descendants of a process 4) Quit program and tree memory Enter selection: 2 Enter the parent process 1d: 0 Process list: Process id: a Parent process: a Child process: 1 Process id: 1 Parent process: 0 Process creation and destruction 1) Initialize process hierarchy 2) Create a new child process 3) Destroy all descendants of a process 4) Quit program and free memory Enter selection: 2 Enter the parent process id: 0 Process 11st: Process 1d: 0 Parent process: a child process: 1 child process: 2 Process 1d: 1 Parent process: 0 Process 1d: 2 Parent process: 0 Process creation and destruction 1) Initialize process hierarchy 2) Create a new child process 3) Destroy a 11 descendants of a process 4) Quit program and free memory Enter selection: 2 Enter the parent process id: 2 Process 11st: Frocess id: 0 . Parent process: 0 child process: 1 child process: 2 Process 1d: 1 Parent process: 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

What causes the nose to be different shapes and sizes?

Answered: 1 week ago