Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CMPS 405-CSE-CENG-QU HW1 Spring 2019 Shell Goal Strengthening students' skills in system programming with using the Clanguage under Linux. Description This is an individual homework.

image text in transcribedimage text in transcribedimage text in transcribed

CMPS 405-CSE-CENG-QU HW1 Spring 2019 Shell Goal Strengthening students' skills in system programming with using the Clanguage under Linux. Description This is an individual homework. The provided skeleton code, shell.c, implements the parsing phase in the development of a basic Linux shell. The user entry is a number of commands with their arguments if any. separated by pipes, if any. The parsing phase is already coded to do the following: 1. Infinite loop 1.1. displays a prompt 1.2. reads user's commands on a line 1.3. check few things, 1.3.1. if the user entry is spaces or empty line, then perform next iteration of the loop i.e., continue 1.3.2. if the user entry is a special command, exit, then exit the loop i.e., break 1.4. performs a tokenization i.e., recognize the commands and store them in an array of a given formatted structure. 1.5. calls a function print_commands to display the information about these commands displays the prompt again awaiting for the user to enter another command. You need to commend this call before your submission 2. end Try the current code by compiling and executing it. The user entry is a number of commands with their arguments, if any, separated by pipes, if any. Observe the output of the program to have a better understanding of what is parsed by the parser and how is it stored. Refer to the Notes section to try various types of input. In this homework, you are required to code the execution of the parsed commands to have a basic shell (Command Line Interpreter). Specificly, you are to provide the code for the execute_commands and exexecute_command functions. The user entry is still the same, a number of commands with their arguments, if any, separated by pipes, if any. The output should be the result of the executed commands. CMPS 405-CSE-CENG-QU HWT Spring 2019 Functionality In the skeleton of the given code, you need to code the function to execute the commands execute_commands and replace the call to the print commands function with the call to this function. The function prototype is void execute_commands (struct command my commands [], int no_commands); This function Creates pipes if needed Determines the input and output file descriptors of a command based on the command's order Calls a function execute command to execute a command at a time. This function has the prototype statement int execute_command (char *command, int arge, char *args[], int fd_in, int fd_out ) The execute command function forks a child which does the following . Decides if dup2 is needed for any of the standard input or output based on the values of fd_in and fd_out Uses execvp to execute the command When the function execute_command is called for every command in the array my commands, it starts waiting for all of them to finish. More detailed comments are in the shell.c file. Notes This homework has a skeleton code. You should make your changes to the skeleton code. While developing the code, and before submission, test your code with different user's inputs. Examples include: o Single command without arguments o Single command with arguments o Single command with arguments and random spaces in between o Two commands without arguments separated by a pipe O Two commands without arguments separated by a pipe and random spaces o Two commands with arguments separated by a pipe o Two commands with arguments separated by a pipe and random spaces OTwo commands one with arguments and the other without separated by a pipe OTwo commands one with arguments and the other without separated by a pipe and random spaces o Three commands without arguments separated by pipes O Three commands without arguments separated by pipes and random spaces o Three commands with arguments separated by pipes O Three commands with arguments separated by pipes and random spaces o Three commands some with arguments separated by pipes CMPS 405-CSE-CENG-QU HW1 Spring 2019 Three commands some with arguments separated by pipes and random spaces o Four commands ...etc Academic Honesty This is an individual assignment, meaning that you should work on it alone. All code turned in by a student must be written by that student. Copying code found on the internet or using code from other students is strictly prohibited. Students are permitted to discuss the assignment together, but must not look at each other's code under any circumstances. If code is found to have been shared between students, all students involved will be penalized, including the student who actually wrote the code. Students found to have violated this honesty policy will receive a 0 on the project and may be reported to the Vice President for Student Affairs. Repeat offenders will receive a 0 in the course and will be reported to the Vice President for Student Affairs. Remember: If you are copying code from the Internet into your solution, you are committing academic dishonesty . If you look at another student's code, you are committing academic dishonesty. If you allow another student to look at your code, you are committing academic dishonesty. If you expose your code to or get exposed to others code that is relevant to this homework whoever is that person (student, TA, Lab instructor, anybody) excluding the course constructor (myself) only, you are committing academic dishonesty. Submission You need to submit 1) shell.c only having your code in there. Make sure that you have filled up your information in the comment at the beginning of the shell.c file. Due date You need to submit end of Wednesday February 26, 2020. CMPS 405-CSE-CENG-QU HW1 Spring 2019 Shell Goal Strengthening students' skills in system programming with using the Clanguage under Linux. Description This is an individual homework. The provided skeleton code, shell.c, implements the parsing phase in the development of a basic Linux shell. The user entry is a number of commands with their arguments if any. separated by pipes, if any. The parsing phase is already coded to do the following: 1. Infinite loop 1.1. displays a prompt 1.2. reads user's commands on a line 1.3. check few things, 1.3.1. if the user entry is spaces or empty line, then perform next iteration of the loop i.e., continue 1.3.2. if the user entry is a special command, exit, then exit the loop i.e., break 1.4. performs a tokenization i.e., recognize the commands and store them in an array of a given formatted structure. 1.5. calls a function print_commands to display the information about these commands displays the prompt again awaiting for the user to enter another command. You need to commend this call before your submission 2. end Try the current code by compiling and executing it. The user entry is a number of commands with their arguments, if any, separated by pipes, if any. Observe the output of the program to have a better understanding of what is parsed by the parser and how is it stored. Refer to the Notes section to try various types of input. In this homework, you are required to code the execution of the parsed commands to have a basic shell (Command Line Interpreter). Specificly, you are to provide the code for the execute_commands and exexecute_command functions. The user entry is still the same, a number of commands with their arguments, if any, separated by pipes, if any. The output should be the result of the executed commands. CMPS 405-CSE-CENG-QU HWT Spring 2019 Functionality In the skeleton of the given code, you need to code the function to execute the commands execute_commands and replace the call to the print commands function with the call to this function. The function prototype is void execute_commands (struct command my commands [], int no_commands); This function Creates pipes if needed Determines the input and output file descriptors of a command based on the command's order Calls a function execute command to execute a command at a time. This function has the prototype statement int execute_command (char *command, int arge, char *args[], int fd_in, int fd_out ) The execute command function forks a child which does the following . Decides if dup2 is needed for any of the standard input or output based on the values of fd_in and fd_out Uses execvp to execute the command When the function execute_command is called for every command in the array my commands, it starts waiting for all of them to finish. More detailed comments are in the shell.c file. Notes This homework has a skeleton code. You should make your changes to the skeleton code. While developing the code, and before submission, test your code with different user's inputs. Examples include: o Single command without arguments o Single command with arguments o Single command with arguments and random spaces in between o Two commands without arguments separated by a pipe O Two commands without arguments separated by a pipe and random spaces o Two commands with arguments separated by a pipe o Two commands with arguments separated by a pipe and random spaces OTwo commands one with arguments and the other without separated by a pipe OTwo commands one with arguments and the other without separated by a pipe and random spaces o Three commands without arguments separated by pipes O Three commands without arguments separated by pipes and random spaces o Three commands with arguments separated by pipes O Three commands with arguments separated by pipes and random spaces o Three commands some with arguments separated by pipes CMPS 405-CSE-CENG-QU HW1 Spring 2019 Three commands some with arguments separated by pipes and random spaces o Four commands ...etc Academic Honesty This is an individual assignment, meaning that you should work on it alone. All code turned in by a student must be written by that student. Copying code found on the internet or using code from other students is strictly prohibited. Students are permitted to discuss the assignment together, but must not look at each other's code under any circumstances. If code is found to have been shared between students, all students involved will be penalized, including the student who actually wrote the code. Students found to have violated this honesty policy will receive a 0 on the project and may be reported to the Vice President for Student Affairs. Repeat offenders will receive a 0 in the course and will be reported to the Vice President for Student Affairs. Remember: If you are copying code from the Internet into your solution, you are committing academic dishonesty . If you look at another student's code, you are committing academic dishonesty. If you allow another student to look at your code, you are committing academic dishonesty. If you expose your code to or get exposed to others code that is relevant to this homework whoever is that person (student, TA, Lab instructor, anybody) excluding the course constructor (myself) only, you are committing academic dishonesty. Submission You need to submit 1) shell.c only having your code in there. Make sure that you have filled up your information in the comment at the beginning of the shell.c file. Due date You need to submit end of Wednesday February 26, 2020

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_2

Step: 3

blur-text-image_3

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

What were some of the team roles at Casper?

Answered: 1 week ago

Question

What were some of the team norms at Casper?

Answered: 1 week ago