Question: Write a small shell - called shhh - that has the following capabilities: 1. Can execute a command with the accompanying arguments. 2. Recognize multiple

Write a small shell - called shhh - that has the following capabilities: 1. Can execute a command with the accompanying arguments. 2. Recognize multiple pipe requests and handle them. 3. Recognize redirection requests and handle them. 4. Type "exit" to quit the shhh shell. Example commands: shhh> cat fred.c shhh> ls -al > output.dat shhh> ls | wc shhh> linect < file.dat | stats > out.dat shhh> prog -x | prog1 | prog2 -2 | prog3 shhh> ls -al | grep -n net | wc > out.dat The shell shhh should always wait for ALL the commands to finish. The topology of the forked processes should be linear children; e.g the shell should have as many children as there are processes needed - with pipes connecting adjacent children.You may assume that any redirection in the command is specified like the third example above. E.g. "redirection in" ( < ) is always specified before the first pipe appears and "redirection out" ( > ) is always after the last pipe specified. To make life easier for you, you may assume that only commands with correct syntax are typed in. In other words don't worry about errors in the formation of the commands. The partial program is available in TRACS, lab2.c. The command parsing part is already done in the program. On your part, you need to implement the above functions.

/** partial example

#include  main() { char *path, *argv[20], buf[80], n, *p; int m, status, inword, continu; while(1) { inword = 0; p = buf; m = 0; continu=0; printf( " shhh> "); while ( ( n = getchar() ) != ' ' || continu ) { if ( n == ' ' ) { if ( inword ) { inword = 0; *p++ = 0; } } else if ( n == ' ' ) continu = 0; else if ( n == '\\' && !inword ) continu = 1; else { if ( !inword ) { inword = 1; argv[m++] = p; *p++ = n; } else *p++ = n; } } *p++ = 0; argv[m] = 0; if ( strcmp(argv[0],"quit") == 0 ) exit (0); if ( fork() == 0 ) { execvp( argv[0], argv ); printf ( " didn't exec "); } wait(&status); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!