Question: This question requires you to write a shell script for bash or zsh . Task: Write a bash ( or zsh ) shell script that

This question requires you to write a shell script for bash or zsh.
Task: Write a bash (or zsh) shell script that accepts exactly two arguments from the
command-line. The first argument is meant to be a filename of a text file and the second
one is the name of a directory. This script should perform the following:
a) Display an appropriate error message and terminate if the number of arguments is
not exactly 2.
b) If the file (specified in argument 1) does not exist, then display an appropriate error
message and terminate.
c) Otherwise, save all the lines in that file that contains the word special in a file
called special.txt in the directory specified as argument 2. If this directory does
not exist in the current directory, then create it.
d) If the file special.txt already exists in the directory specified, then those lines of
text extracted from argument 1 should be appended to special.txt.
Submission Requirement: Submit only your script file. Your script file MUST be named
extract.sh
Your script file should be documented with appropriate comments. Make sure your
name and student ID are at the top of the file.
2024 AUT 2
Question 2: C Struct and Pointers (Max Mark: 40/100)
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 (i.e. a small process control block). You may refer to the code in
prog4.c in Lab 3 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 List_item definition in prog4.c 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 1-15-20 and the process ID of the new PCB is 7. Then
it should be inserted after process ID 1 and before 15, resulting in 1-7-15-20. The
function prototype of insert should be:
int insert(struct List_item *listHead, struct List_item *insertItem);
where listHead points to the head of the linked list, insertItem points to the list
item to be inserted. This function should return 1 if the insertion is successful
and 0 if not. Insertion could be unsuccessul due to several reasons, e.g.
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 delete(struct List_item *listHead, int pid);
where pid is the process ID of the PCB to be removed. This function should
return 1 if the deletion is successful, and 0 if nothing has been deleted, e.g.
process ID not found.
2024 AUT 3
(c) The third function, to be named printList, performs the same function as the last
section of the main() function in prog4.c 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 printList(struct List_item *listHead);
The code of these 3 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 3
insertions and 3 deletions where at least 1 insertion and 1 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 file(s).
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!