Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- Implement a shell simulator in user mode (in C language). - The execution of a command in the shell should be conditional (if else)

- Implement a shell simulator in user mode (in C language).

- The execution of a command in the shell should be conditional (if else) such as the following:

_____________________________________________________________________________________________________________________________________________________

int main (int argc , char **argv) {

while (1) { /* repeat until cmd is exit */

printPrompt(); /* indicate shell is ready */

cmdLine = readCommandLine(); /* read until user hits ENTER */

cmd = parseCommand(cmdLine); /* command & options in array */

if (isInternalCommand(cmd)){ /* internal command */

executeInternalCommand(cmd);

} else { /* external command */

pid = fork(); /* create a child process */

if (pid == 0) {

executeCommand(cmd); /* let child execute execve() */

} else if (pid > 0) {

chld = waitpid (&status); /* wait for completion of child */

} else { /* it is an error */ }

}

}

}

_____________________________________________________________________________________________________________________________________________________

Instructions:

1- Keep the same structure of the main function and add other functions to it.

2- The cmd prompt of the custom shell must start with "CS>".

3- The shell executes the command, if it is an external command, by fork(2)-ing the main process and having the child execute the command using execve(2). Refer to the man page for an example code. The parent should use a function of the wait(2) family to wait for the completion of the foreground child process before continuing. If the command is internal, the shell executes it in its own address space without creating a new process. Your solution must implement the command.

4- The shell must handle cd, help, exit, pwd, and one more cmd of your choice. each command must be implemented using System call(s). for example:

- printf(3) is not a system call, but write(2) is.

- Use help(1) for a listinf of internal cmds

- Use "man syscalls" for a listing of system calls.

5- Your version of the help command displays the internal commands implemented in your solution with a synosis for each. Follow the style of the Linux shell help(1) command output. Make sure to show implemented command options

6- If the user enters the command exit, the shell shall exit successfully using a corresponding system call without calling fork(2)

_____________________________________________________________________________________________________________________________________________________

Edit: this is exactly what the homework says, please ask specific question on what clarifications you might need.

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

1.The difference between climate and weather?

Answered: 1 week ago

Question

1. What is Fog ?

Answered: 1 week ago

Question

How water vapour forms ?

Answered: 1 week ago

Question

What is Entrepreneur?

Answered: 1 week ago

Question

Which period is known as the chalolithic age ?

Answered: 1 week ago