Question: Can somebody please write a complete C code for this? Please, I really need it. A small shell with I/O redirections Write a C program

 Can somebody please write a complete C code for this? Please,I really need it. A small shell with I/O redirections Write aC program (techshell.c) that repeatedly allows a user to enter input (interpreted

Can somebody please write a complete C code for this? Please, I really need it.

A small shell with I/O redirections Write a C program (techshell.c) that repeatedly allows a user to enter input (interpreted as a shell command). Your program first should parse the command line and determine whether it contains I/O redirection ( for output to a file). The command line is then executed in a forked child process that uses an exec call. Your program should provide an informative shell prompt that contains the current working directory, followed by a $, and ending with a space. The prompt should be updated if the current working directory changes. Here's an example that illustrates this: /home/ibrahim $cd.. /home $ You must include a separate file called README (a text file with no extension) that provides the following details: (1) Your name (and your partner's name if applicable); (2) The inner workings of your program; and (3) If you have not fully implemented shell functionality as described above, list the parts that work (and how to test them if it's not obvious) so that you can receive partial credit. You must also include output from testing your program using script, a program that records terminal sessions. See the sample at the end of this document. A script session of your program is started (and saved in a file called typescript) by typing script from the command line, running your program, testing it, exiting it, and finally exiting script as follows (example): script Script started, file is typescript $. /techshell cd Desktop Desktop\$ exit $ exit exit Script done, file is typescript $ Make sure to implement good programming practices. For example, your main function should merely be a driver (i.e., farm out various functions to subroutines). Submit a single .zip archive file that contains the following: (1) The README file described above; (2) All .c source files required to compile your program (do not include any executable or object files); and (3) Output from testing your program via script; make sure to demonstrate: 1. Simple UNIX commands; 2. I/O redirection (); and 3. Error conditions (e.g., invalid commands, errors, etc). our program should be able to handle the following examples (via sample script output). Note that your rogram will be tested with more than these commands (including more error handling cases): ./techshell cd Desktop Desktop\$ pwd /home/ibrahim/Desktop Desktop\$ cd .. $ pwd /home/ibrahim $1s - hh techshell.c -rw-re-r-- 1 ibrahim ibrahim 3.9K Oct 27 15:08 techshell.c $ chmod 400 techshell.c $1s-lh techshell.c -r----- 1 ibrahim ibrahim 3.9K Oct 27 15:08 techshell.c $1s/root 1s: cannot open directory /root: Permission denied $ horseface Error 2 (No such file or directory) $cd/ root Error 13 (Permission denied) $ ps PID TTY TIME CMD 6271pts/300:00:00 bash 7415pts/300:00:00 techshell 7460pts/300:00:00ps $ whereis ps ps: /bin/ps /usr/share/man/man 1/ps.1.gz \$ /bin/ps u USER PID \&CPU \&MEM VSZ RSS TTY STAT START TIME COMMAND ibrahim 4440.00.072365244pts/1 Sst 07:570:01bash ibrahim 62710.00.072205032 pts/3 Ss 14:180:00 bash ibrahim 74150.00.021721324 pts/3 S+ 15:080:00./ techshell ibrahim 74830.00.052282372 pts/3 R+ 15:120:00psu $1s Desktop Documents Music techshell Downloads Pictures techshell.c Videos $ ps u>ps.out $ wC 1 wc.out $ cat wc.out 5 $1s Desktop Documents Music techshell Downloads Pictures techshell.c Videos ps.out wc.out $rm ps.out wc. out $1s Desktop Documents Music techshell Downloads Pictures techshell.c Videos $exit $ Iake sure to comment your source code appropriately, and to include a header providing your name(s). Jote: - In order to receive a grade for this assignment, you need to demo your work to the instructor. - You may work in groups of two for this project (after express approval from the instructor). - Do not use the system(...) function Hints: (1) To get the value of an environment variable, getenv is your friend; (2) The exec function of most use may very well be execvp; (3) The following may just work to redirect stdin from a file: FILE* infile = fopen (my_input_file, "r"); dup2 (fileno(infile), 0); fclose(infile); (4) The following may just work to redirect stdout to a file: FILE* outfile = fopen (my_output_file, "w"); dup2 (fileno (outfile), 1); fclose (outfile) ; (5) To build command line arguments, malloc and realloc are your friend; (6) To copy strings, you may want to try strdup; (7) To handle errors, errno and strerror are your friends; and (8) \#define DEBUG may greatly help with debugging (i.e., use toggle-able print statements). Grading rubric: - Your program compiles with no errors (50 pts) - I/O redirections work (50 pts) - All other commands handled through an exec function (60pts) - Invalid user input handled correctly (20 pts) - README file provided ( 20pts) I suggest having the following structure for your program. / Functions de implement: char* CommandPrompt (; / / Display current working directory and return user input struct ShellCommand ParseCommandLine(char* input); // Process the user input (As a shell command) void ExecuteCommand(struct ShellCommand command); //Execute a shell command int main 0//MAIN \{ char input; struct ShellCommand command; // repeatedly prompt the user for input \{ input = CommandPrompt 0 ; // parse the command line command = ParseCommandLine(input); // execute the command ExecuteCommand(command); \} exit(0) \}

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!