a would appreciate any help with the program below

Assignment Unix Process Spawner.


This assignment requires each student to develop a C++ program, called spawn, that acts as a UNIX command interpreter. Spawn will fork a new process(es) and change its program context based on the command line arguments given to it. Consequently, spawn's arguments will be any command sequence that you would ordinarily give to the shell program itself, with some exceptions and modifications, e.g. $./spawn ls -l /home/jbloggs.

The program must be developed on the Red Hat Linux server pqlinux.wit.ie.

Spawn must also handle i/o redirection and piping, or though these will be encoded in a manner different from the norm in order to avoid the shell interpreting them first. The symbols to be used by spawn are:

-o : redirect standard output
-e : redirect standard error
% : the pipe symbol.
Also, different from the norm, redirection will be positioned at the beginning of the command line sequence [Piping will be as normal].


Formt 1:

spawn [-o filename] [-e filename] command_sequence

Command-sequence is any utility/program invocation that would normally be supplied at the command line.

For this format spawn must fork a new process and change its program context to command_sequence. If output and/or error redirection is requested then this must be carried out BEFORE the context change.

Example 1:

$ ./spawn ls -l /home/jbloggs

...... output from ls utility ......


Example 2:

$ ./spawn chmod g+x /home/jbloggs/file1


[The access rights of file1 will have been altered accordingly.]

Example 3:

$ ./spawn -o list.dat ls -l /home/jbloggs


[New list.dat file contains long listing of the jbloggs directory.]

Example 4:

$ ./spawn -e ch.err chmod p+r file1


[New ch.err file contains an error message generated by the chmod process ]

Spawn must also be able to handle both redirection at the same time where, for maximum flexibility, these can be listed in any order.

Example 5:

$ ./spawn -e list.err -o list.dat ls -l /home/jbloggs


$ ./spawn -o list.dat -e list.err ls -l /home/jbloggs

Formt 2:

spawn [-o filename] [-e filename] command_seq_1 [ % command_seq_2]

When the pipe symbol (%) is included in the command line arguments, spawn must perform the following steps:

Create a pipe 'file'.
Fork TWO new processes.
Redirect the standard output of one process to the pipe and change its program context to command_seq_1
Redirect the standard input of the second process from the pipe and change its program context to command_seq_2.
Example 6:

$ ./spawn ls -l /home/jbloggs % wc -l

7 [i.e. there are 7 files in the jbloggs directory]


[This is equivalent to the shell command,

$ ls -l /home/jbloggs | wc -l (try it).]

Example 6:

$ ./spawn -o argv.tmp head +20 foreign.cxx % grep 'argv'


[argv.tmp will have each of the first 20 lines from foreign.cxx that contain the substring 'argv'.]

[This is equivalent to the shell command,

$ head +20 foreign.cxx | grep 'argv' > argv.tmp ]

Example 7:

$ ./spawn -e count.err ls -l /home/jbloggs % gryp '.cxx'


[ count.err will have an error message indicating that there is no utility called gryp.]

Error handling:

Spawn's error handling is confined to validating the usage of the 'special symbols'. To this end it must check the following:

There must be at least two strings after the occurence of -e / -o in the command line.
There must be at least one string after the occurence of % in the command line.
% cannot appear before -e / -o in the command line.
Spawn does not need to validate the command_sequences as the exec() function will take care of this.

thanks very much