Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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. Sample commands: shhh>ls shhh>ls -t -al shhh>cat file.txt (file.txt is an existing file) shhh>ls -al > output.txt And then open output.txt to see if the content is correct or not shhh> ls | more | wc shhh>./pre < input.txt | ./sort > output.txt (./pre and ./sort are the executable from proj1. input.txt is the file that provides the input and output.txt is the output file) shhh> exit 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 below. The command parsing part is already done in the program. On your part, you need to implement the above functions.
Partial Program:
#includemain() { 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],"exit") == 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started