Project 1: Implementing a Shell

Similar documents
UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this

HW 1: Shell. Contents CS 162. Due: September 18, Getting started 2. 2 Add support for cd and pwd 2. 3 Program execution 2. 4 Path resolution 3

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

Review of Fundamentals

1 The Var Shell (vsh)

Implementation of a simple shell, xssh

CST Algonquin College 2

Implementation of a simple shell, xssh

Lab 2: Linux/Unix shell

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

This homework is due by 11:59:59 PM on Thursday, October 12, 2017.

Week 5 Lesson 5 02/28/18

Lab 2: Implementing a Shell COMPSCI 310: Introduction to Operating Systems

CS 4410, Fall 2017 Project 1: My First Shell Assigned: August 27, 2017 Due: Monday, September 11:59PM

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan

5/8/2012. Specifying Instructions to the Shell Chapter 8

CS167 Programming Assignment 1: Shell

Programming Assignment #1: A Simple Shell

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

CSE506: Operating Systems CSE 506: Operating Systems

System Programming. Introduction to Unix

SOFTWARE ARCHITECTURE 3. SHELL

Operating System Labs. Yuanbin Wu

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

CSE506: Operating Systems CSE 506: Operating Systems

UNIX Kernel. UNIX History

Unix Processes. What is a Process?

Process Management! Goals of this Lecture!

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

5/20/2007. Touring Essential Programs

A Brief Introduction to the Linux Shell for Data Science

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CS 470 Operating Systems Spring 2013 Shell Project

Essentials for Scientific Computing: Bash Shell Scripting Day 3

UNIX Shell Programming

DATA 301 Introduction to Data Analytics Command Line. Dr. Ramon Lawrence University of British Columbia Okanagan

Why learn the Command Line? The command line is the text interface to the computer. DATA 301 Introduction to Data Analytics Command Line

CS 213, Fall 2002 Lab Assignment L5: Writing Your Own Unix Shell Assigned: Oct. 24, Due: Thu., Oct. 31, 11:59PM

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

GMI-Cmd.exe Reference Manual GMI Command Utility General Management Interface Foundation

Introduction to Linux

Introduction to UNIX Shell Exercises

What to Do? Convert pathnames to common interface. Different ways to access files. Absolute pathname

Operating System Interaction via bash

Bamuengine.com. Chapter 7. The Process

CSCI Computer Systems Fundamentals Shell Lab: Writing Your Own Unix Shell

Process Management 1

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

PESIT Bangalore South Campus

Project 2: Shell with History1

CS Unix Tools & Scripting

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

CSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm

Shells and Shell Programming

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

do shell script in AppleScript

UNIX System Programming Lecture 3: BASH Programming

Shells and Shell Programming

Introduction to Linux

(In columns, of course.)

Part 1: Basic Commands/U3li3es

CSC374, Spring 2010 Lab Assignment 1: Writing Your Own Unix Shell

Introduction to Linux Spring 2014, Section 02, Lecture 3 Jason Tang

Manual Shell Script Linux If File Exists Wildcard

Shell Programming Overview

The Command Shell. Fundamentals of Computer Science

Bash Programming. Student Workbook

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

CS 213, Fall 2001 Lab Assignment L5: Writing Your Own Unix Shell Assigned: Oct. 25, Due: Fri., Nov. 2, 11:59PM

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Creating a Shell or Command Interperter Program CSCI411 Lab

Scripting Languages Course 1. Diana Trandabăț

Bash command shell language interpreter

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

The Shell, System Calls, Processes, and Basic Inter-Process Communication

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

UNIX Essentials Featuring Solaris 10 Op System

Processes. CS3026 Operating Systems Lecture 05

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

(MCQZ-CS604 Operating Systems)

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

CS Unix Tools. Lecture 3 Making Bash Work For You Fall Hussam Abu-Libdeh based on slides by David Slater. September 13, 2010

PROGRAMMING PROJECT ONE DEVELOPING A SHELL

Linux File System and Basic Commands

Processes. Sanzheng Qiao. December, Department of Computing and Software

Command-line interpreters

Process life and death. Tuesday, September 28, 2010

COMS 6100 Class Notes 3

Science One CS : Getting Started

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

CSC 352, Fall 2015 Assignment 3 Due: Wednesday, September 16 at 23:59:59

Overview of the UNIX File System

Transcription:

Assigned: August 28, 2015, 12:20am Due: September 21, 2015, 11:59:59pm Project 1: Implementing a Shell Purpose The purpose of this project is to familiarize you with the mechanics of process control through the implementation of a shell user interface. This includes the relationship between child and parent processes, the steps needed to create a new process, including search of the path, and an introduction to user-input parsing and verification. Furthermore, you will come to understand how input/output redirection, pipes, and background processes are implemented. Problem Statement Design and implement a basic shell interface that supports input/output redirection, pipes, background processing, and a series of built in functions as specified below. The shell should be robust (e.g. it should not crash under any circumstance beyond machine failure). The required features should adhere to the operational semantics of the bash shell. Project Tasks You are tasked with implementing a basic shell. The specification below is divided into parts. When in doubt, test a specification rule against bash. You may access bash on linprog.cs.fsu.edu by logging in and typing the command bash. The default shell on linprog is tcsh. Part 1: Parsing Before the shell can begin executing commands, it needs to extract the command name, the arguments, input redirection (<), output redirection (>), piping ( ), and background execution (&) indicators. Understand the following segments of the project prior to designing your parsing. The ordering of execution of many constructs may influence your parsing strategy. It is also critical that you understand how to parse arguments to a command and what delimits arguments. Part 2: Environmental Variables Every program runs in its own environment. One example of an environmental variable is $USER, which expands to the current username. For example, if my current username is 'dennis', typing => echo $USER yields => dennis In the bash shell, you can type 'env' to see a list of all your environmental variables. You will need to use and expand various environmental variables in your shell, and you may use the getenv() library call to do so. The getenv() procedure searchs the environment list for a string that matches the string pointed to by name. The strings are of the fom: NAME = VALUE

Part 3: Prompt The prompt should always indicate to the user the absolute working directory, who they are, and the machine name. Remember that cd can update the working directory. This is the format: USER@MACHINE: PWD => Example: dennis@linprog3: /home/grads/dennis/cop4610t => Part 4: Path Resolution You will need to convert different file path naming conventions to absolute path names. You can assume that directories are separated with a single forward slash (/). Directories that can occur anywhere in the path.. Expands to the parent of the current working directory Signal an error if used on root directory. Expands to the current working directory (the directory doesn't change) DIR Expands to the child of the current working directory named DIR Signal an error if DIR doesn't exist Signal an error if DIR occurs before the final item and is not a directory Directories that can only occur at the start of the path ~ Expands to $HOME directory / Root directory Files that can only occur at the end of the path FILE Expands to the child of the current working directory named FILE Signal an error if FILE doesn't exist You will need to handle commands slightly differently. If the path contains a '/', the path resolution is handled as above, signaling an error if the end target does not exist or is not a file. Otherwise, if the path is just a single name, then you will need to prefix it with each location in the $PATH and search for file existence. The first file in the concatenated path list to exist is the path of the command. If none of the files exist, signal an error. Part 5: Execution You will need to execute simple commands. First resolve the path as above. If no errors occur, you will need to fork out a child process and then use execv to execute the path within the child process. Part 6: I/O Redirection

Once the shell can handle simple execution, you'll need to add the ability to redirect input and output from and to files. The following rules describe the expected behavior CMD > FILE CMD redirects its output to FILE Create FILE if it does not exist Overwrite FILE if it does exist CMD < FILE CMD receives input from FILE Signal an error if FILE does not exist or is not a file Signal an error for the following CMD < < FILE < CMD > > FILE > Part 7: Pipes After it can handle redirection, your shell is capable of emulating the functionality of pipes. Pipes should behave in the following manner: CMD1 CMD2 CMD1 redirects its standard output to CMD2's standard input CMD1 CMD2 CMD3 CMD1 redirects its standard output to CMD2's standard input CMD2 redirects its standard output to CMD3's standard input CMD1 CMD2 CMD3 CMD4 CMD1 redirects its standard output to CMD2's standard input CMD2 redirects its standard output to CMD3's standard input CMD3 redirects its standard output to CMD4's standard input Signal an error for the following CMD CMD Part 8: Background Processing You will need to handle execution for background processes. There are several ways this can be encountered: CMD & Execute CMD in the background When execution starts, print

[position of CMD in the execution queue] [CMD's PID] When execution completes, print [position of CMD in the execution queue]+ [CMD's command line] & CMD Executes CMD in the foreground Ignores & & CMD & Behaves the sames as CMD & Ignores first & CMD1 CMD2 & Execute CMD1 CMD2 in the background When execution starts, print [position in the background execution queue] [CMD1's PID] [CMD2's PID] When execution completes, print [position in the background execution queue]+ [CMD1 CMD2 command line] CMD > FILE & Follow rules for output redirection and background processing CMD < FILE & Follow rules for input redirection and background processing Signal an error for anything else Examples includes CMD1 & CMD2 & CMD1 & CMD2 CMD1 > & FILE CMD1 < & FILE Part 9: Built-ins exit Terminates your running shell process and prints Exiting Shell... Example dennis@linprog3: /home/grads/dennis/cop4610t => exit Exiting Shell... (shell terminates) cd [PATH] Changes the present working directory according to the path resolution above If no arguments are supplied, it behaves as if $HOME is the argument Signal an error if more than one argument is present Signal an error if the target is not a directory echo Outputs whatever the user specifies For each argument passed to echo If the argument does not begin with $ Output the argument without modification

If the argument begins with $ Look up the argument in the list of environment variables Print the value if it exists Signal an error if it does not exist etime [COMMAND] Record the start time using gettimeofday() execute the rest of the arguments as per typical execution Record the end time using gettimeofday() Output the elapsed time in the format of s.us where s is the number of seconds and us is the number of micro seconds (0 padded) Example dennis@linprog3: /home/grads/dennis/cop4610t => etime sleep 1 Elapsed Time: 1.000000s limits [COMMAND] Execute the supplied commands Record /proc/<pid>/limits while it executes You only need to get the Max file size, Max Open Files, Max Processes, and Max Pending signals When it finishes, output each of the recorded values Example dennis@linprog3: /home/grads/dennis/cop4610t => limits time Restrictions real 0m0.00s user 0m0.00s sys 0m0.00s Max file size unlimited unlimited bytes Max open files 1024 4096 files Max processes 127574 127574 processes Max pending signals 127574 127574 signals Must be implemented in the C Programming Language Only fork() and execv() can be used to spawn new processes You can not use system() or any of the other exec family of system calls Output must match bash unless specified above Allowed Assumptions No more than three pipes ( ) will appear in a single line You do not need to handle globs, regular expressions, special characters, quotes, escaped characters, etc Yo do need to handle expansion of environment variables ls $HOME prints contents of home directory $SHELL loads standard shell $UNDEFINED

error, undefined environment variable The user input will be no more than 255 characters Pipes and I/O redirection will not occur together Multiple redirections of the same type will not appear You do not need to implement auto-complete You need to handle zombie processes The above decomposition of the project tasks is only a suggestion, you can implement the requirements in any order You do not need to support built in commands that are not specified Extra Credit Support multiple pipes (limited by the OS and hardware instead of just 3), input redirection, and output redirection all within a single call. A novel, useful utility of your choosing. You must provide a written specification on the proper operation of your utility. Submission Procedure Follow the procedures given in the syllabus. Remember to remove executables and object files that were created before submitting.