Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 parentchild 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 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 in which case the program terminates use strcmp to compare the command with
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 stdgnu 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
myshellq
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started