Question: ANSWER IN C LANGUAGE PLEASE, MUST COMPILE Objective: To simulate process creation and destruction when implemented with linked lists. Specification: The program creates/destroys child processes
ANSWER IN C LANGUAGE PLEASE, MUST COMPILE
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
--------SAMPLE OUTPUT------------
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: 1 Process list: Process id: 0 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 list: Process id: 0 Parent process: 0 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 list: Process id: 0 Parent process: 0 Child process: 1 Child process: 2 Process id: 1 Parent process: 0 Process id: 2 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: 2 Process list: Process id: 0 Parent process: 0 Child process: 1 Child process: 2 Process id: 1 Parent process: 0
Process id: 2 Parent process: 0 Child process: 3 Process id: 3 Parent process: 2 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 list: Process id: 0 Parent process: 0 Child process: 1 Child process: 2 Child process: 4 Process id: 1 Parent process: 0 Process id: 2 Parent process: 0 Child process: 3 Process id: 3 Parent process: 2 Process id: 4 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: 3 Enter the parent process whose descendants are to be destroyed: 2 Process list: Process id: 0 Parent process: 0 Child process: 1 Child process: 2 Child process: 4 Process id: 1 Parent process: 0 Process id: 2 Parent process: 0 Process id: 4 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: 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
