Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i need some guidance on how to implement for this assignment. This is implement shell.c in Linux in C language This is what I'm given
i need some guidance on how to implement for this assignment. This is implement shell.c in Linux in C language
This is what I'm given so far for shell.c to implementing this assignment in bold
#include
struct node { struct node* next; char * command; };
int main(){
}
Part 1: Reading Input and Parsing In this section, you are to take input from user using function call fgets (To understand about any function, please refer to linux manual, e.g. if you want to understand how gets works, type man gets in your terminal and you will get standard documentation on how it works, or google the Linux manual page for that function). Your code should support multiple line commands and flags concurrently. You are to use the fputs to print output to user. 2.1 Reading input The input in linux standard commands take 4 forms: commands one character flag (identified by single -) multi characters flags (identified by double-) command symbols (1,,&) For example the following command: 1s. -a --author prints current directory files, authors, and all internal files too, etc. Your code is supposed to take unknown number of flags commands concurrently and parse it.For each command, a new process should be created (via 'fork); and pipes for connecting output/input among processes will be needed if necessary. To do so, you are to form one linked list with each entry in it is one argument/command For example, if the user is to type echo "hello world" | ls -a --author Your linked list will be one command/argument in each link. For this example, it will be the following nodes: echo "hello world" . author 2.2 Printing Output For first part, we do not process the arguments, thus you are required just to print it back in the following order: list of commands user enters, and then each command and its flags. Example: Following the same example above, your part1 code should output the following: Commands: echo echo: "hello world" 1s: -a --author ete.. You are to use POSIX and libc functions only for this part (i.e. malloc, standard data types, and create your linked list struct). Note: Your program should run like a proper shell (i.e. in a while loop that takes one line of arguments, processes, and waits for next, etc.) 3 Executing Commands In this section, you are requested to execute the commands you just read from the user and stored in your data structure. You are to use the following Linux system calls to implement the requested methods: fork, erecup, erit, waitpid, dup2, pipe, open, close, getcwd, chdir (remember to use man to know what each system call does. You can also find man pages online, e.g., https://linux.die.net/man/) You are to support the following commands: echo hello > file.txt (i.e. output redirection) cat (i.e. changing directory) xterm & 4 Bonus This section is optional (but we encourage taking a look and trying some of it). 4.1 Is function (7% bonus) You have implemented cd in your assignment, but to see it working and how it behaves, it is nice to implement is that will show the files in current directory. Hint: Take a look at the following library functions: readdir linkl, opendir link2, and scandir link3 4.2 x86 inline assembly c (30% bonus) Implement putchar and getchar functions using x86 inline assembly. After implementing assembly e function, create wrapper to put a string and read string with specific size accord- ingly. Hint: Take a look at the following: first tutorial and Second tutorial intro to inline assembly Linux System calls Part 1: Reading Input and Parsing In this section, you are to take input from user using function call fgets (To understand about any function, please refer to linux manual, e.g. if you want to understand how gets works, type man gets in your terminal and you will get standard documentation on how it works, or google the Linux manual page for that function). Your code should support multiple line commands and flags concurrently. You are to use the fputs to print output to user. 2.1 Reading input The input in linux standard commands take 4 forms: commands one character flag (identified by single -) multi characters flags (identified by double-) command symbols (1,,&) For example the following command: 1s. -a --author prints current directory files, authors, and all internal files too, etc. Your code is supposed to take unknown number of flags commands concurrently and parse it.For each command, a new process should be created (via 'fork); and pipes for connecting output/input among processes will be needed if necessary. To do so, you are to form one linked list with each entry in it is one argument/command For example, if the user is to type echo "hello world" | ls -a --author Your linked list will be one command/argument in each link. For this example, it will be the following nodes: echo "hello world" . author 2.2 Printing Output For first part, we do not process the arguments, thus you are required just to print it back in the following order: list of commands user enters, and then each command and its flags. Example: Following the same example above, your part1 code should output the following: Commands: echo echo: "hello world" 1s: -a --author ete.. You are to use POSIX and libc functions only for this part (i.e. malloc, standard data types, and create your linked list struct). Note: Your program should run like a proper shell (i.e. in a while loop that takes one line of arguments, processes, and waits for next, etc.) 3 Executing Commands In this section, you are requested to execute the commands you just read from the user and stored in your data structure. You are to use the following Linux system calls to implement the requested methods: fork, erecup, erit, waitpid, dup2, pipe, open, close, getcwd, chdir (remember to use man to know what each system call does. You can also find man pages online, e.g., https://linux.die.net/man/) You are to support the following commands: echo hello > file.txt (i.e. output redirection) cat (i.e. changing directory) xterm & 4 Bonus This section is optional (but we encourage taking a look and trying some of it). 4.1 Is function (7% bonus) You have implemented cd in your assignment, but to see it working and how it behaves, it is nice to implement is that will show the files in current directory. Hint: Take a look at the following library functions: readdir linkl, opendir link2, and scandir link3 4.2 x86 inline assembly c (30% bonus) Implement putchar and getchar functions using x86 inline assembly. After implementing assembly e function, create wrapper to put a string and read string with specific size accord- ingly. Hint: Take a look at the following: first tutorial and Second tutorial intro to inline assembly Linux System callsStep 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