PROGRAM DESCRIPTION:

In this assignment, you will write a complete C program that will act as a simple command-line interpreter (i.e., a shell) for the Linux kernel. In writing your shell, you are expected to use the fork-exec-wait model. In particular, you are to implement the following:

  • Loop continuously until the user enters quit, which exits your shell.
  • Inside the loop, you will print your "minor3" prompt and read in the user's command, which may consist of a Linux command with 0 or more options and arguments supported by the command. You are expected to read in and process only 1 command at a time with no pipelining or redirection, but you must be able to handle any options and arguments supported by the command. Note that shell built-in commands, such as cd, history, and exit, are not expected to work as they are built-in to the shell itself.
  • In a child process, you are to execute the command as given, including all options and arguments given. If the command is not valid, rather than display an "exec failed" message as shown in class examples, you will simply print out the command itself with command not found as shown in the SAMPLE OUTPUT and then exit the child process. The parent process should wait for the child process to finish.

SAMPLE OUTPUT

$ ./a.out
minor3> ls
a.out grades.txt rec01.txt testdir phone.txt route.txt who.txt du.txt rec01.c file1 rec01sol.c minor3.c
minor3> ls -a -l -t
total 144
-rwx------ 1 mat0299 mat0299 7835 Feb 14 17:39 a.out
drwx------ 4 mat0299 mat0299 4096 Feb 14 17:39 .
-rw------- 1 mat0299 mat0299 2665 Feb 14 17:39 minor3.c
-rw------- 1 mat0299 mat0299 33 Feb 5 03:30 du.txt
-rw------- 1 mat0299 mat0299 33 Feb 5 01:28 file1
-rw------- 1 mat0299 mat0299 333 Feb 5 01:02 route.txt
drwx------ 2 mat0299 mat0299 4096 Feb 3 20:36 testdir
-rw------- 1 mat0299 mat0299 116 Feb 2 23:38 who.txt
-rw------- 1 mat0299 mat0299 52 Jan 24 11:15 phone.txt
-rw------- 1 mat0299 mat0299 200 Jan 19 02:37 grades.txt
-rw------- 1 mat0299 mat0299 1634 Jan 2 15:08 rec01.c
-rw------- 1 mat0299 mat0299 160 Jan 2 14:58 rec01.txt
-rw------- 1 mat0299 mat0299 1451 Jan 2 14:58 rec01sol.c
drwx------ 18 mat0299 mat0299 4096 Dec 12 21:04 ..
minor3> ls -alt
total 144
-rwx------ 1 mat0299 mat0299 7835 Feb 14 17:39 a.out
drwx------ 4 mat0299 mat0299 4096 Feb 14 17:39 .
-rw------- 1 mat0299 mat0299 2665 Feb 14 17:39 minor3.c
-rw------- 1 mat0299 mat0299 33 Feb 5 03:30 du.txt
-rw------- 1 mat0299 mat0299 33 Feb 5 01:28 file1
-rw------- 1 mat0299 mat0299 333 Feb 5 01:02 route.txt
drwx------ 2 mat0299 mat0299 4096 Feb 3 20:36 testdir
-rw------- 1 mat0299 mat0299 116 Feb 2 23:38 who.txt
-rw------- 1 mat0299 mat0299 52 Jan 24 11:15 phone.txt
-rw------- 1 mat0299 mat0299 200 Jan 19 02:37 grades.txt
-rw------- 1 mat0299 mat0299 1634 Jan 2 15:08 rec01.c
-rw------- 1 mat0299 mat0299 160 Jan 2 14:58 rec01.txt
-rw------- 1 mat0299 mat0299 1451 Jan 2 14:58 rec01sol.c
drwx------ 18 mat0299 mat0299 4096 Dec 12 21:04 ..
minor3> sdjdsf
sdjdsf: command not found
minor3> cd ..
cd: command not found
minor3> quit
$
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.