Answered step by step
Verified Expert Solution
Link Copied!

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 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions