Question: Question 2 Write a C program ( name it shell.c ) to develop a basic Unix shell interface to execute basic Unix commands input by

Question 2
Write a C program (name it shell.c) to develop a basic Unix shell interface to execute basic Unix
commands input by the user. This program will use parent-child process to run the commands that are
entered by the user. The parent process will print the shell prompt "myshell>" where the user will input
the Unix commands. The parent process will parse the input and identify the command along with
arguments and child will execute using execvp() function. You can call following functions to
implement the program:
while (1) loop creates an infinite loop for the shell to continuously accept commands.
fgets () is used to read a command from the standard input.
strtok () is used to split the command into arguments (for use with execvp ()).
fork () creates a new process, and execvp () replaces the child process with a new program.
wait () is used in the parent process to wait for the completion of the child process.
After the command is executed (or not), the main menu is reproduced again, unless the command
is 'q' in which case the program terminates (use strcmp () to compare the command with 'q'
to exit the program).
If the user press enter without entering command, then programme should show "myshell>"
prompt again and be ready to accept new command. The other implementation details are at your
discretion, and you are free to explore.
Use the following command to compile the code:
$ gcc -Werror -Wall -g -std=gnu99 shell.c -o shell
The above code will create the ./shell executable file
The expected output for executing:
When running on Linux Terminal the command ./shell. It will print the prompt and you can enter any
Unix command:
myshell> echo hello
hello
myshell> uname
Linux
myshell> touch file.txt
myshell>q
 Question 2 Write a C program (name it shell.c) to develop

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 Databases Questions!