代写辅导接单-Shell Lab: Writing Your Own Linux Shell

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top

18-213/18-613, Fall 2023

Shell Lab: Writing Your Own Linux Shell

Assigned: Mon, November 7th

Due: Thurs, Mon, November 20th, 11:59PM Last Possible Handin: Thu, November 23rd, 11:59PM

1 Introduction

The purpose of this assignment is to help you become more familiar with the concepts of process control and signalling. You’ll do this by writing a simple Linux shell program, tsh (tiny shell), that supports a simple form of job control and I/O redirection. Please read the whole writeup before starting.

2 Logistics

This is an individual project. All handins are electronic. You must do this lab assignment on a class shark machine.

To get your lab materials, click "Download Handout" on Autolab. Clone your repository on a Shark machine by running:

$ git clone https://github.com/18-x13/tshlab-<YOUR USERNAME>. git

3 Overview

Looking at the tsh.c file, you will see that it contains a skeleton of a simple Linux shell. It will not, of course, function as a shell if you compile and run it now. To help you get started, we’ve provided you with a helper file, tsh_helper.{c,h}, which contains the implementation of routines that manipulate a job list, and a command line parser. Read the header file carefully to understand how to use it in your shell.

Your assignment is to complete the remaining empty functions listed below.

eval: Main routine that parses, interprets, and executes the command line. sigchld_handler: Handles SIGCHLD signals.

sigint_handler: Handles SIGINT signals (sent by Ctrl-C).

sigtstp_handler: Handles SIGTSTP signals (sent by Ctrl-Z).

When you wish to test your shell, type make to recompile it. To run it, type tsh to the command line: 1

 

linux> ./tsh

tsh> [type commands to your shell here]

4 General Guidelines for Writing Your Shell

This section provides an overview of how you can start writing your shell. You should read Section 4: The tsh Specification, for a list of everything your shell should support and the format of all shell output.

A shell is an interactive command-line interpreter that runs programs on behalf of the user. A shell repeatedly prints a prompt, waits for a command line on stdin, and then carries out some action, as directed by the contents of the command line.

Each command consists of one or more words, the first of which is the name of an action to perform. This may either be the path to an executable file (e.g., tsh> /bin/ls), or a built-in command— a word with special meaning to the shell—(e.g., tsh> quit). Following this are command-line arguments to be passed to the command.

Built-in commands run within the shell’s process. Looking at the handout code, you may notice that it’s difficult to exit the program. Try making it respond to the word quit.

So as not to corrupt its own state, the shell runs each executable in its own child process. You should recall from lecture the sequence of three library calls necessary to create a new process, run a particular executable, and wait for a child process to end. Try to make your shell correctly respond to /bin/ls, without breaking the existing quit command. If this works, try passing ls a particular directory to make sure your shell is passing the arguments along.

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468