Functions
- fork :
creates a new process
- strtok
: Used on solaris to replace strsep (used in your book)
- getenv
: returns the string associated with some environment variable
- malloc:
memory allocation in C, you may use new if you compile with the g++
compiler
- argv
and argc: arguments to programs
- printf:
prints output to the console i.e. cout
- scanf:
reads input from keyboard i.e. cin or getline
Shell Functionality
- Shell
reads commands from keyboard, the <return> tells it to parse the
command line for the command and arguments (options and data)
- Shell
has to find the command (using PATH)
- Shell
creates a new process with fork() to execute the command
- The
child process executes the command while the shell waits.
- The
program of the child process reads the file with the command, and that
program reads the data and performs its duty
Launch Program (Example from Chapter 2)
- The
launch program is used as:
- Launch
launch_script
- Where
launch_script is a file containing a set of commands to execute.
- Launch
reads the file, and executes each of the commands in a manner similar to a
shell.
- ParseCommand(É)
This function uses strsep and is given in your textbook. I have a
rewritten version for you to copy from
~hardnett/pub/cis343/lab2/parsecommand.txt
Strategy
- You
need to understand this program first, by typing it in, running it and
getting it to work. Then you will be ready to tackle the minishell
program.
- A
sample executable of ms can be executed:
% ~hardnett/pub/cis343/demos/ms
Your program should have the same
behavior.