Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a code in c for linux operating system. 1)the semicolon command like (echo HELLO; ls -l ) have to work well 2) and the

Write a code in c for linux operating system.

1)the semicolon command like (echo "HELLO"; ls -l ) have to work well

2) and the variable command like (VAR=AAA ---> VAR=/bin/ls ....) have to work well

Do some checks for all the details and attach it to see.

Pay attention to all the questions and all the details in all the questions.

Exercise definition:

Implement a simple shell in the C language under the Linux operating system. The shell will display a prompt to the user, read the commands and send them to the operating system for execution. And the three characteristics are (1) prompt (2) semicolon (3) variable environment. After running our shell program (which will be called 1ex) the user can type commands including arguments, and insight will run the command the user entered.

Envelope requirements will be as follows:

1. Input of a command from the user.

a. The maximum length of the command including the arguments is 510 characters.

b. The maximum number of arguments is 10. If there are more than 10 arguments the command will be set as invalid.

c. No limit can be placed on the number of characters of each argument (or of the template name) but their sum is less than 510!

d. Between one argument and another there can be several spaces, but it can be assumed that there are no other characters between them (bemo ('r', 't'

2. Running the command The commands will be sent to the operating system for execution using the fork and execvp commands. The lecture will be by having the template create a child process. The son will be the one who will actually run the command using the execvp command.

3. Execution of the cd command Do not execute. Every time the user presses cd. must be output "cd not supported".

4. The shell will exit whenever Enter is typed three times in a row. That is three times an empty command. Let's clarify, if Enter is typed twice and then a command (legal or not) the count is reset. That is, if and only if there are three consecutive Enter times, only then exit. Additional requirements/emphasis:

5. The following command is valid: echo "hi john" We will note, for a kind of "edge case" in the aspect, the number of arguments. Apparently, it is 3 Arguments (three plays separated by a margin). But because of the quotation marks the command refers to 2 arguments. echo

6. Your internal realization of a mechanism for dynamically setting variables in the shell and using them.

7. It is allowed to use the execvp command only once in the feature as well as fork. In other words, avoid duplicating code.

8. You must support orders that are separated by; can appear with one or more spaces or without a space between them).

● /bin/ls;/bin/ls

● /bin/ls ; /bin/ls

9. The prompt that you are required to complete has the following structure:

#cmd:|#args:@current dir>

when:

number of command >> -must be replaced with the number of the legal commands entered so far.

number of total args >>-must be replaced with the number of arguments of the legal commands entered so far. In order to get the current folder you can use the getcwd command. (Exact parameters and methods of use can be found on Google). You are not limited to these functions .

More details and technical recommendations:

1. In case of an error in allocating memory or creating a child process, an ERR error will be printed and the shell will exit.

2. The program will wait for the completion of the son process (wait command hint) before displaying the prompt line in order to allow additional input.

3. Additional useful commands in the exercise are: A. exec strtok, strchr, strcmp, strcpy, strlen. b. strtok changes the string it works on - if you want to go over the same string twice, create two copies of it.

4.Check the shell for commands such as man, echo, ls, cat, more, expr, sleep

5. Be sure to free memory!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

a simple shell implementation in C for the Linux operating system that fulfills the given requiremen... 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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Operating System questions