7_shell - Part 7: Shell Design CS252: Systems Programming...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Part 7: Shell Design CS252: Systems Programming Ramana Kompella Computer Science Department Purdue University
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
UNIX Organization q UNIX has multiple components Ø Scheduler – Schedules processes Ø File System – Provides storage Ø Virtual Memory - Allows each process to have its own address space Ø Networking Subsystem Ø Windowing System Ø Shells and applications
Background image of page 2
Shell Project q To interact with the OS you use a shell program or command interpreter Ø Csh – C Shell Ø Tcsh – Enhanced C Shell Ø Sh - Shell Ø Ksh – Korn Shell Ø Bash – GNU shell q There are also other graphical shells like Ø Windows Desktop Ø Mac OS Finder Ø X Windows Managers
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Shell Interpreter q The shell project is divided into several subsystems: q Parser : reads a command line and creates a command table. One entry corresponds to a component in the pipeline. Example: Command: ls –al | grep me > file1 ls -al grep me In:dflt Out:file1 Err:dflt Command Table
Background image of page 4
Shell Interpreter q Executor: Ø Creates new process for each entry in the command table. Ø It also creates pipes to communicate the output of one process to the input of the next one. Ø Also it redirects the stdinput, stdoutput, and stderr. A | b | c | d > out < in •All pipe entries share the same stderr
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Shell Interpreter q Other Subsystems Ø Environment Variables: Set, Print, Expand env vars Ø Wildcards: Arguments of the form a*a are expanded to all the files that match them. Ø Subshells: Arguments with ``(backticks) are executed and the output is sent as input to the shell.
Background image of page 6
Shell Project q Part 1: Shell Parser. Ø Read Command Line and print Command Table q Part 2: Executer: Ø Create Processes and communicate them with pipes. Also do in/out/err redirection. q Part 3: Other Subsystems: Ø Wildcard, Env. vars, Subshells
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lex and Yacc q A parser is divided into a lexical analyzer that separates the input into tokens and a parser that parses the tokens according to a grammar. q The tokens are described in a file shell.l using regular expressions. q The grammar is described in a file shell.y using syntax expressions. q Shell.l is processed with a program called lex that generates a lexical analyzer. q Shell.y is processed with a program called yacc that generates a parser program
Background image of page 8
Shell Project Shell.l Parser characters Executor Command Table Wildcard and Envars ls -al a* grep me In:dflt Out:file1 Err:dflt ls –al a* | grep me > file1 shell.y Lexer <ls> <–al> <a*> <PIPE> <grep> <me> <GREAT> Final Command Table ls -al aab aaa grep me In:dflt Out:file1 Err:dflt
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
q You need to implement the following grammar in shell.l and shell.y DNE<BSH>±<]DNE<BSH>±>±<<²GJMFOBNF><³GJMFOBNF> <²´GJMFOBNF><²²GJMFOBNF><²²´GJMFOBNF>>±<´> q Currently, the grammar implemented is very simple q Examples of commands accepted by the new grammar.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/06/2012 for the course CS 252 taught by Professor Gustavorodriguez during the Spring '11 term at Purdue University-West Lafayette.

Page1 / 78

7_shell - Part 7: Shell Design CS252: Systems Programming...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online