Question: C Struct and Pointers ( Max Mark: 4 0 / 1 0 0 ) The C programs you are required to write for this question
C Struct and Pointers Max Mark:
The C programs you are required to write for this question will be compiled using gcc on either Linux or MacOS for marking.
Task: You are required to write three C functions that maintains a linked list of simple process information ie a small process control block You may refer to the code in progc in Lab as a starting point.
Each process control block PCB should be represented as a C structure that consists of
a A process ID an int
b Process name a char array
You will need to provide the definition of this structure and use typedef to give this structure a name. You will also need to modify the Listitem definition in progc so that it contains a pointer to this structure. The int is no longer needed.
The three C functions are described as follows:
a The first function, to be named insert, inserts a new PCB into the list. The position where this PCB is to be inserted depends on its process ID The resulting list should be ordered by the process ID For example, if the process IDs of the existing items in the list are and the process ID of the new PCB is Then it should be inserted after process ID and before resulting in The function prototype of insert should be:
int insertstruct Listitem listHead struct Listitem insertItem;
where listHead points to the head of the linked list, insertItem points to the list item to be inserted. This function should return if the insertion is successful and if not. Insertion could be unsuccessul due to several reasons, eg duplicated process ID
b The second function, to be named delete, removes a PCB from the list. The PCB to be removed is specified by its process ID The function prototype of delete should be:
int deletestruct Listitem listHead int pid;
where pid is the process ID of the PCB to be removed. This function should return if the deletion is successful, and if nothing has been deleted, eg process ID not found.
AUT
c The third function, to be named printList, performs the same function as the last section of the main function in progc that prints information of the items in this case the process ID and the name of the process on the list. The function prototype should be:
void printListstruct Listitem listHead;
The code of these functions should be in a file named listfuncs.c The main function should be placed in a file named main.c
Further Requirement: You should modify the main function to provide at least insertions and deletions where at least insertion and deletion is unsuccessful. Print the list information after each insertion or deletion using printList to show the result of that operation.
Your program should use appropriate header files
Submission Requirements: Submit only your main.c listfuncs.c and associated header files. Your submission will be compiled using the command:
gcc main.c listfuncs.c o main
So make sure your programs could be compiled without error either on Ubuntu or MacOS using this command and the resulting program runs as required.
Your source code files should be documented with appropriate comments. Make sure your name and student ID are at the top of each file.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
