Question
Building a Command Line Interpreter (myshell) 1.Goal of this programming assignment The primary goal of this assignment is to understand and gain some familiarity with
Building a Command Line Interpreter (myshell)
1.Goal of this programming assignment
The primary goal of this assignment is to understand and gain some familiarity with
the system call interface in Unix Environment. In this assignment you will be
implementing your own command line interpreter like a Unix shell program.
YOU ARE NOT IMPLEMENTING COMMANDS!
YOUR program should just
FORK off programs and EXECUTE them.
2.
Requirements
(1)
Programming language: You have to use either C or C++ to develop your program.
(2)
Running Environment: Your program should be compiled at
CSEGRIDand be able tobe tested without errors.
3.
The implementation details
(1)
Backgrounds: The command line interpreter, called a shell, is an application program
that gets commands from a keyboard and uses the system call interfaces to invoke OS
functions.
(2)
Your shell should support followings:
(a)
Support exit or stop
your shell command
a)
Example(s): exit
(b)
Support commands with no arguments
.
a)
Examples: ls, pwd, whoami and hostname
(c)
Support commands with arguments:
a)
Examples: ls l, ls fx, ps aux ,date u, cd directory, etc.
(d)
A command, with or without arguments, whose output is redirected to a file
a)
Examples: ls > foo, ls -Fx > foob
(e)
A command, with or without arguments, whose input is redirected from a file
a)
Examples: sort < testfile
(f)
Supporting a sequence of programs that communicate through a pipe.
a)
Examples: ls | wc
(g)
Display error messages if the typed command has errors or cant be found
2
4.
Hint
Your shell should isolate itself from program failures by creating a child process to
execute each command specified by the user. For example, the tar cvf cli5678 program1
command is executed by a child of the process executing the shell, myshell.
% tar cvf cli5678 program1
You might consider the following functions to build myshell:
(1)
Printing a prompt when myshell is begun, it display its own string as its own prompt.
For example, myshell> .
(2)
Getting command line
To get a command line, the shell performs a blocking read
operation so that the process that executes the shell will be blocked until the user types
a command line in response to the prompt. When the user enters the command, the
comm
and line string should be returned to the myshell.
(3)
Parsing the command: Take the user command and divide it into command and
arguments as well as checking errors.
(4)
Finding the file The shell provides a set of environment variables for each user
such as PATH. The PATH environment variable is an ordered list of absolute
pathnames that specifies where the shell should search for command files.
(5)
Create a child process and launch the command
Once the command and arguments
are prepared, create a child process to execute the command with its arguments and
wait until the command is completed.
Someone help to solve this Operating Systems problem?
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