a2 - cs201 - due in 2 weeks (feb 4). ------------------------------------- small shell - overview ------------------------- Write a small basic UNIX shell that parses commands, and executes them. Note that we expect to be able to execute only simple commands without shell redirection or pipes. Basically you should be able to execute: cat, cp, ls and various other simple commands with and without arguments. E.g, % ls -l % cat file1 file2 file3 file4 % cp file target % rm file1 file2 and the like. Note that you may need to have a built-in path; e.g,. first try ., then try /bin, then try /usr/bin. More complex commands like commands that assume visual terminal control commands (emacs, vi, and the like) may not work -- this is ok. Nor do we expect % ls | wc to work or ls > file. Roughly your shell should do the following: 1. take an input string and parse it into words separated by white space (tabs, blanks, and the like). It should read one line at a time (newline terminated). Your shell should exit at EOF (control-d). 2. execute the command using fork, execvp, wait, and exit. I.e., the shell should fork a child, let the child call exec, and wait for the child to terminate. Be careful about forking; i.e., run ps or ps -elf (or top) to make sure you do not have vast amounts of escaped children. This may be due to the parent exiting with the children still running or for other reason where the parent terminates before it can call wait. 3. add three built-in commands: 3.1 % myshell string .... Call system(3) to execute string. This is more or less what your shell should do without the "myshell" verb. This is very easy. 3.2 % mydebug Reprint the last command, and show whether it was a built-in command or not (myshell/mydebug/chdir). This is a very primitive history. 3.3 % chdir somedirectory The current working directory is an attribute of the running process. In other words, you need to make a system call to change the shell's directory. In the next assignment, we will enhance this shell so try to do a good job. Turn-in ------- 1. an ASCII report showing tests executed (use script). 2. Makefile 3. *.c and any *.h source code. System calls ------------- 1. system(3) 2. chdir(2) 3. fork(2), execvp(2), wait(2), exit(2)