Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help in C code. Code layout is below. #include #include /* Define structures and global constants, including: the pcb type, the children linked list

Please help in C code. Code layout is below.

image text in transcribed

image text in transcribed

#include #include

/* Define structures and global constants, including: the pcb type, the children linked list type, the maximum number of processes*/

/***************************************************************/ void "PROCEDURE TO PRINT HIERARCHY OF PROCESSES"() { /* declare local vars */ /* for each process index i from 0 up to (but not including) maximum number of processes*/ /* if PCB[i] is not NULL */ /* print process id, parent id, list of children processes */ } /* end of procedure */

/***************************************************************/ void "PROCEDURE FOR OPTION #1"() { /* declare local vars */ /* Allocate memory for PCB[0] */ /* Intitialize all other PCB's to NULL */ /* print hierarchy of processes */ return; } /* end of procedure */

/***************************************************************/ void "PROCDURE FOR OPTION #2"() { /* define local vars */ /* prompt for parent process index p */ /* if PCB[p] is NULL, print message process does not exist, return */ /* search for first available index q without a parent in a while loop */ /* if maximum number of processes reached, print message of no more avaiable PCBs */ /* allocate memory for new child process, initialize fields */ /* record the parent's index p in PCB[q] */ /* initialize the list of children of PCB[q] as empty */ /* append the node containing the child's index q to the children linked list of PCB[p] */ /* print hierarchy of processes */ return; } /* end of procedure */

/***************************************************************/ void "RECURSIVE PROCEDURE TO DESTROY CHILDREN PROCESSES"(parameter) { /* declare local vars */ /* check if end of linked list--if so return */ /* else call self on next node in linked list */ /* set variable q to current node's process index field */ /* call self on children of PCB[q] */ /* free memory of PCB[q] and set PCB[q] to NULL*/ /* free memory of paramter and set to NULL */ return; } /* end of procedure */

/***************************************************************/ void "PROCEDURE FOR OPTION #3"() { /* declare local vars */ /* prompt for process index p */ /* call recursive procedure to destroy children of PCB[p] */ /* reset children of PCB[p] to NULL */ /* print hierarchy of processes */ return; } /* end of procedure */

/***************************************************************/ void "PROCEDURE FOR OPTION #4"() { /* if PCB[0] is non null) /* if children of PCB[0] is not null */ /* call recursive procedure to destroy children of PCB[0] */ /* free memory of all PCB's */ return; } /* end of procedure */

/***************************************************************/ int main() { /* declare local vars */ /* while user has not chosen to quit */ /* print menu of options */ /* prompt for menu selection */ /* call appropriate procedure based on choice--use switch statement or series of if, else if, else statements */ return 1; /* indicates success */ } /* end of procedure */

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_child0 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 0 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 What NOT to do: - Do NOT modify the choice values (1,2,3,4) or input characters and then try to convert them to integers--the test script used for grading your assignment will not work correctly. - Do NOT turn in an alternate version of the assignment downloaded from the Internet (coursehero, chegg, reddit, github, ChatGPT, etc.) or submitted from you or another student from a previous semester - the test cases from this semester will not work on a previous semester's assignment. - Do NOT turn in your assignment coded in another programming language ( C++,C, Java). What to turn in: - The source code as a C file uploaded to Canvas by the deadline of 11:59pm PST (20% per consecutive day for late submissions, up to the 4th day - note 1 minute late counts as a day late, 1 day and 1 minute late counts as 2 days late, etc.) - As a note, even though your code may compile on a compiler you have installed on your computer, I do not have access to your computer. I will be using the following free online compiler for testing, so make sure your code compiles with the following online C compiler before submitting: https://www.onlinegdb.com/online_c_compiler If it does not compile with the above compiler, the default grade is 0 points since I cannot run it. 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 1 ist: Process id: 0 Parent process: 0 Process creation and destruction 1) Initialize process hierarchy 2) Create a new child process 3) Destroy al1 descendants of a process 4) Quit program and free memory Enter selection: 2 Enter the parent process id: 0 Process 1ist: 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 1ist: Process id: 0 Parent process: 0 Child process: I 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 Iist: Process id: 0 Parent process: 0 Child process: 1 Child process: 2 . Process id: 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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions