logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

create your own shell by adding all the features described in the BLS lecture

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

100 Points

Summary

Use the code in CSAPP2, 8.4.6 "Using fork and execve to Run Programs" as a starting point to develop and test a small version of a shell that forks processes in the foreground and/or the background.

What To Do

Follow the directions in BLS "How the Shell Works" lecture.

Start with program shellex.c from figures 8.22-8.24 and create your own shell by adding all the features described in the BLS lecture: read and parse command line, run command in foreground or background, implement redirection, implement pipe.

Notes:

Note 1: Although a real shell can accept a command line with an arbitrary number of pipes, in this homework it is sufficient to implement just one pipe. So, your shell should be able to handle correctly a command line like

command-1 | command-2 < input-file > output-file &

Notice that the placement of "< input-file" and "> output-file" in the command line is not critical since "< input-file" redirects the input of command-1 and "> output-file" redirects the output of command-2. If there is no pipe, "> output-file" redirects the output of command-1.

Note 2: Your shell program can execute programs in the current directory but does not inherit PATH automatically, so

> ls

does not work, but

> /usr/bin/ls works

and, this works (when myspin is in the current directory)

> myspin 10 &

 

Note 3: Files csapp.c, csapp.h, shellex.c, myspin.c are in FILES/PROGRAMS To compile and run shellex.c do the following

gcc -c csapp.c

gcc -o shellex shellex.c csapp.o -lpthread

 

 

 

/* $begin shellmain */ #include "csapp.h"

 

#define MAXARGS 128

 

/* function prototypes */ void eval(char*cmdline);

int parseline(char *buf, char **argv); int builtin_command(char **argv);

 

int main()

{

char cmdline[MAXLINE]; /* command line */

 

while (1) {

/* read */ printf("> ");

Fgets(cmdline, MAXLINE, stdin); if (feof(stdin))

exit(0);

 

/* evaluate */ eval(cmdline);

}

}

/* $end shellmain */

 

/* $begin eval */

/* eval - evaluate a command line */ void eval(char *cmdline)

{

char *argv[MAXARGS]; /* argv for execve() */

char buf[MAXLINE]; /* holds modified command line */ int bg; /* should the job run in bg or fg? */

pid_t pid; /* process id */

 

strcpy(buf, cmdline);

bg = parseline(buf, argv); if (argv[0] == NULL)

return; /* ignore empty lines */

 

if (!builtin_command(argv)) {

if ((pid = Fork()) == 0) { /* child runs user job */ if (execve(argv[0], argv, environ) < 0) {

printf("%s: Command not found.\n", argv[0]); exit(0);

}

}

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

894 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

716 Answers

Hire Me
expert
Husnain SaeedComputer science

527 Answers

Hire Me
expert
Atharva PatilComputer science

574 Answers

Hire Me

Get Free Quote!

404 Experts Online