Project 4
In this project you need to continue working on the shell program. This time you need to implement
the features:
- If user used & in the command line, you need to execute the program(s) user specified just like
you did at the first part, but this time you do not need to wait for this program to stop. Instead, you need
to keep information about the running process in a special data structure.
- Built-in command ps now should print the list of all currently working processes in the form:
process_id process_name
- Built-in command kill should take one argument, the process ID, and terminate the process
with the given ID.
- Built-in command killall should kill all the current processes.
- Command exit now should stop all the child processes before exiting the shell.
- Special thread cleaner should periodically look for normally terminated processes where information
would be still in your process list and, then wipe out this info. In other words, ps command should not
print the programs that have been terminated (either by user or by kill command).
- Make sure that threads that want to access process information (like ps, kill, cleaner)
cannot access it at the same time. If one thread is currently accessing this data, another should be blocked
until the first one is done.
- Piping. If user uses | in the command line, you need to re-direct the standard output of the
first program and the standard input of the second one. You need to create an anonymous pipe and make these two
processes read/write to the pipe instead of using standard input/output.
- Make sure that user can redirect standard output of all built-in commands. That is, user should be able to run
a command like:
> ps | sort
- Program source should be split into several files (both types .cpp and .h) according to your
logic. You should also provide a makefile to built the program.
Some details of the implementation.
You need to create an abstract class TTask that keeps all information about a task (process or thread)
currently running by the shell program, some common methods like Print(), and virtual method
Kill(). The classes TProcess and TThread
should be the derived classes from the class TTask. In this classes you need to implement the method Kill.
Please also implement class TParser that parses a given string returning; that is, does the same job
as the old function ParseCommandLine. However, implementing this as a class, you may get rid of passing the
parameters back and forth between the functions (I mean ParseCommandLine and NexeWord) and also
create a convenient interface to the result of the parsing.
Please also write a function StartTask that takes all needed information to start a task
(either a process or a thread) and creates an instance of the corresponding object. This function should return
a pointer to the newly create element of the TTask object. Do not forget to do all redirection for
processes and threads.
Due day is Sunday, April
27, 2003 at 11:59pm.