Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to learn to develop multi-process programs. Y ou are expected to extend the myshel1.c program and add pipelines and

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

The purpose of this assignment is to learn to develop multi-process programs. Y ou are expected to extend the myshel1.c program and add pipelines and I/O redirections. In particular, your shell program should recognize the following 1.-Redirect standard output from a command to a file. Note: if the file already exist, it will be erased and overwritten without warning. For example, COP4338$ 1s 1 COP4338$ sort myshell.c 2 Note that you're not supposed to implement the unix commands (Is, sort, ...). You do need to implement the shell that invoke these commands and you need to "wire" up the standard input and output so that they "chain" up as expected 2. -Append standard output from a command to a file if the file exists; if the file does notexist create one. For example, create one. For example, COP4338 sort myshell.c 1 COP4338 echo "Add A Line" >> 1 3. 1 COP4338 sort > 1 output Make sure you have your parent process fork the children and 'wire them up using pipes accordingly. There will be spaces separating tokens in the command line Y our program should be able to run with all the unix commands as expected. Don't assume your program will only be tested by the above commands. Also, there could be more than two commands chained by pipes, like the second example above Your program should be able to run with all the unix commands as expected. Don't assume your program will only be tested by the above commands. Also, there could be more than two commands chained by pipes, like the second example above. Y our program needs to provide necessary sanity-check from the user input. Prompt meaningful errors accordingly as what you'd experience with your shell. Hint: use strtok() functions to separate the tokens and use strs tr() to locate sub-strings. S ubmit a zip file Firs tnamelastnameA 3.zip (of course, you'd use your real name here). You should place the source code and the Makefile in the directory. One should be able to create the executable by simply make'. The Makefile should also contain a 'clean' target for cleaning up the directory (removing all temporary files, object files and executa ble files). Make sure you don't include intermediate files: .o, executables, , etc., in your submission. (There'll be a penalty for including unnecessary intermediate files). /* This example is stolen from Dr. Raju Rangaswami's original 4338 demo and modified to fit into our lecture. */ #include include #include include #include stdio.h> #define MAX ARGS 20 #define BUFSIZ 1024 int get args(chan* cmdline, chan* args[]) int i-0; / if no args */ if((args[e] strtok(cmdline, "Int"))NULL) return 8; while((args[++1] strtok(NULL, " \t ")) !-NULL) { = if(i { >-MAX ARGS) printf(Too many arguments!n) exit(1); /* the last one is always NULL */ return i void execute(char* cmdline) int pid, async; void execute(char cmdline) int pid, async; char* args [MAX ARGS]; int nargs get args(cmdline, args); if(nargs 0) /* parent process */ if(lasync) waitpid(pid, NULL, 0); else printf ("this is an async call ); else / error occurred / perror("fork failed") exit(1); int main (int argc, chan* argv [1) int main (int argc, char* argv l) char cmdline[BUFSIZ]; for(;;) printf("COP4338; if (fgets (cmdline, BUFSIZ, stdin) NULL) perror(fgets failed") exit (1); execute(cmdline); return 0; The purpose of this assignment is to learn to develop multi-process programs. Y ou are expected to extend the myshel1.c program and add pipelines and I/O redirections. In particular, your shell program should recognize the following 1.-Redirect standard output from a command to a file. Note: if the file already exist, it will be erased and overwritten without warning. For example, COP4338$ 1s 1 COP4338$ sort myshell.c 2 Note that you're not supposed to implement the unix commands (Is, sort, ...). You do need to implement the shell that invoke these commands and you need to "wire" up the standard input and output so that they "chain" up as expected 2. -Append standard output from a command to a file if the file exists; if the file does notexist create one. For example, create one. For example, COP4338 sort myshell.c 1 COP4338 echo "Add A Line" >> 1 3. 1 COP4338 sort > 1 output Make sure you have your parent process fork the children and 'wire them up using pipes accordingly. There will be spaces separating tokens in the command line Y our program should be able to run with all the unix commands as expected. Don't assume your program will only be tested by the above commands. Also, there could be more than two commands chained by pipes, like the second example above Your program should be able to run with all the unix commands as expected. Don't assume your program will only be tested by the above commands. Also, there could be more than two commands chained by pipes, like the second example above. Y our program needs to provide necessary sanity-check from the user input. Prompt meaningful errors accordingly as what you'd experience with your shell. Hint: use strtok() functions to separate the tokens and use strs tr() to locate sub-strings. S ubmit a zip file Firs tnamelastnameA 3.zip (of course, you'd use your real name here). You should place the source code and the Makefile in the directory. One should be able to create the executable by simply make'. The Makefile should also contain a 'clean' target for cleaning up the directory (removing all temporary files, object files and executa ble files). Make sure you don't include intermediate files: .o, executables, , etc., in your submission. (There'll be a penalty for including unnecessary intermediate files). /* This example is stolen from Dr. Raju Rangaswami's original 4338 demo and modified to fit into our lecture. */ #include include #include include #include stdio.h> #define MAX ARGS 20 #define BUFSIZ 1024 int get args(chan* cmdline, chan* args[]) int i-0; / if no args */ if((args[e] strtok(cmdline, "Int"))NULL) return 8; while((args[++1] strtok(NULL, " \t ")) !-NULL) { = if(i { >-MAX ARGS) printf(Too many arguments!n) exit(1); /* the last one is always NULL */ return i void execute(char* cmdline) int pid, async; void execute(char cmdline) int pid, async; char* args [MAX ARGS]; int nargs get args(cmdline, args); if(nargs 0) /* parent process */ if(lasync) waitpid(pid, NULL, 0); else printf ("this is an async call ); else / error occurred / perror("fork failed") exit(1); int main (int argc, chan* argv [1) int main (int argc, char* argv l) char cmdline[BUFSIZ]; for(;;) printf("COP4338; if (fgets (cmdline, BUFSIZ, stdin) NULL) perror(fgets failed") exit (1); execute(cmdline); return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago