Question: create a xv 6 small shell in c , has to follow this template, only putting code where the comments say. it needs to execute
create a xv small shell in c has to follow this template, only putting code where the comments say. it needs to execute simple commands including cd implelemt input output redirects, pipes, multi element pipelines and the ; operator which allows commands to run one after another in one line. the hardest part i find is implement cd and the ; operator. #include "kerneltypesh
#include "useruserh
#include "kernelfcntlh
Read a line of characters from stdin.
int getcmdchar buf int nbuf
##### Place your code here
return ;
A recursive function which parses the command
at buf and executes it
attributenoreturn
void runcommandchar buf int nbuf, int pcp
Useful data structures and flags.
char arguments;
int numargs ;
Word startend
int ws ;
int we ;
int redirectionleft ;
int redirectionright ;
char filenamel ;
char filenamer ;
int p;
int pipecmd ;
int sequencecmd ;
int i ;
Parse the command character by character.
for ; i nbuf; i
Parse the current character and setup various flags:
sequencecmd redirection, pipecmd and similar.
##### Place your code here.
if redirectionleft redirectionright
No redirection, continue parsing command.
Place your code here.
else
Redirection command. Capture the file names.
##### Place your code here.
Sequence command. Continue this command in a new process.
Wait for it to complete and execute the command following ;
if sequencecmd
sequencecmd ;
if fork
wait;
##### Place your code here.
If this is a redirection command,
tie the specified files to std inout
if redirectionleft
##### Place your code here.
if redirectionright
##### Place your code here.
Parsing done. Execute the command.
If this command is a CD command, write the arguments to the pcp pipe
and exit with to tell the parent process about this.
if strcmpargumentscd
##### Place your code here.
else
Pipe command: fork twice. Execute the left hand side directly.
Call runcommand recursion for the right side of the pipe.
if pipecmd
##### Place your code here.
else
##### Place your code here.
exit;
int mainvoid
static char buf;
int pcp;
pipepcp;
Read and run input commands.
whilegetcmdbuf sizeofbuf
iffork
runcommandbuf pcp;
Check if runcommand found this is
a CD command and run it if required.
int childstatus;
##### Place your code here
exit;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
