Question
ANSWER IN C LANGUAGE PLEASE Objective: To simulate process creation and destruction when implemented with linked lists. Specification: The program creates/destroys child processes based on
ANSWER IN C LANGUAGE PLEASE
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: o parent: a PCB index corresponding to the process creator o 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: o 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] o 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
*TEST CASES*
1 2 0 2 0 2 2 2 0 3 2 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started