In this assignment, you are tasked to create a shell as well as a daemon process, both of which are the common applications of fork().
The assignment is written entirely in C. At the end of this assignment, you should be able to:
- Create a shell and wait for user input
- Write several other system programs that can be invoked by the shell
- Parse user input and invoke
fork()with the appropriate program - Create a program that results in a daemon process
- Use your shell to keep track of the state of your daemon processes
You may complete this assignment in pairs. Indicate your partner’s name in the google sheet provided in our course handout.
Starter Code
You might want to run this assignment in your POSIX compliant OS, using gcc version 10.X or below. Using version 11.X and above might be okay, but the bot is running gcc 10 version so if you use some newer fancy stuffs then the bot might not be able to run it. You can try first.
You should have joined the GitHub Classroom and obtain the starter code for this assignment there. The link can be found in the Course Calendar portion of your Course Handout.
PA1 Files
You should have the following files:
pa1/
|- bin/source/
|- check_daemon.c
|- count_line.c
|- display.c
|- find.c
|- listdir_all.c
|- listdir.c
|- shell.c
|- shell.h
|- summond.c
|- system_program.h
|- files/
|-combined.txt
|- file1.txt
|- file2.txt
|- intermediate.txt
|- lorem_ipsum.txt
|- notes.pdf
|- oneline.txt
|- paragraph.txt
|- ss.png
|- .gitignore
|- README.md
|- makefile
You will only need to modify four files for this assignment: shell.c, countline.c, summond.c, and checkdaemon.c.
DO NOT modify any directories and file names.
Submission Rules
Type your answer in the spaces provided in each file, labeled as BEGIN ANSWER.
- DO NOT modify any
makefile - DO NOT create more scripts other than what’s given in the starter code
- DO NOT modify any interface (keep original functions as-is)
- DO NOT print anything to the console, other than the provided print statements. Any print statements you used for debugging must be deleted.
Your shell should NOT crash due to any input from the user or any ABSENCE of input from the user after the given command. In other words, if the original code crash in any way even without you modifying it, we meant for you to fix it 🙂.
Preparation
Go to /pa1/ and type make. Then, run the compiled shell ./cseshell. You should see all files compiled and the shell ran and immediately returned as follows:

Notice how you have a few binaries available under /bin. Those are your system programs. We will execute these system programs later on from our shell.

/bin/source
This directory contains the source file of your shell and also 7 system programs.
shell.h
Both files: /bin/source/shell.c and /bin/source/shell.h are the files containing the declaration and implementation for your shell program. The header file (shell.h) contains function declarations, imports, and macro definitions, while the .c file contains the implementation for these functions.
Open /bin/source/shell.h. The first few lines of #includes and #define are libraries and macro definitions.
Next, we have these array of pointers builtin_commands global constant that stores the strings of built-in commands that the user can type into the shell. These commands are implemented in the shell (instead of system programs).
/*
List of builtin commands, followed by their corresponding functions.
*/
const char *builtin_commands[] = {
"cd", // calls shell_cd
"help", // calls shell_help
"exit", // calls shell_exit
"usage", // calls shell_usage
};
Next, is the function declarations of the shell that you will implement in shell.c:
/*
The fundamental functions of the shell interface
*/
char *read_line_stdin(void); // TASK 1
char **tokenize_line_stdin(char *line); // TASK 2
int process_command(char **args); // TASK 3
void main_loop(void); // TASK 4
DO NOT modify ANY of these original functions declared in shell.h: not the arguments, not the names, nothing. Leave it as it is.
.c files
Other .c files inside /bin/source contains the implementation of your system programs. You will only need to modify three system programs: countline.c, summond.c, and checkdaemon.c. The others are already implemented for you.
Expected commands
The following commands are implemented within the shell, and are already done for you:
cd
help
exit
usage
By “done” it means that the functionality has been implemented for you but it does not mean that it will immediately work out of the box because you have not implemented the shell yet. For instance usage will not work because it relies on global variable current_number_tokens which you will need to instantiate later.
This shell also supports: listdir, listdirall, summond, checkdaemon, find, and countline via the system programs in /pa1/bin/.
AGAIN, DO NOT modify any directories and file names.
Your Task
You are to implement:
- Task 1-4: the fundamental functions inside
shell.c(Task 1-4) - Task 5-7: three system program:
countline(Task 5),summond(Task 6), andcheckdaemon(Task 7).