welcome to cse459.11 name: di cao email: [email protected] [email protected] ...

15
Welcome to CSE459.11 Welcome to CSE459.11 Name: Di Cao Name: Di Cao Email: Email: [email protected] Classroom: DL357 Classroom: DL357 Class Time: T 8:30am - 9:18am Class Time: T 8:30am - 9:18am Office : DL680 Office : DL680 Office Hours: 9:30am - Office Hours: 9:30am - 10:30am(T) 10:30am(T)

Upload: marilyn-johnston

Post on 26-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Welcome to CSE459.11Welcome to CSE459.11

Name: Di CaoName: Di Cao Email: Email: [email protected] Classroom: DL357Classroom: DL357 Class Time: T 8:30am - 9:18amClass Time: T 8:30am - 9:18am Office : DL680Office : DL680 Office Hours: 9:30am -10:30am(T)Office Hours: 9:30am -10:30am(T)

Page 2: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Lecture 1: Lecture 1: Introduction to Unix Shell Introduction to Unix Shell

Brief Unix HistoryBrief Unix HistoryRunning Model and System CallsRunning Model and System CallsUnix Shell & FlavorUnix Shell & Flavor

Page 3: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Unix History and MotivationUnix History and Motivation The first version of Unix came from AT&T in the The first version of Unix came from AT&T in the

early 1970s (Unix is old!).early 1970s (Unix is old!). Unix was developed by programmers and Unix was developed by programmers and for for

programmersprogrammers.. Unix is designed so that users can extend the Unix is designed so that users can extend the

functionalityfunctionality To build new tools easily and efficientlyTo build new tools easily and efficiently To customize the shell and user interface. To customize the shell and user interface. To string together a series of Unix commands to create To string together a series of Unix commands to create

new functionality.new functionality. To create custom commands that do exactly what we To create custom commands that do exactly what we

want.want.

Page 4: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

What is Shell?What is Shell?

Shell isShell is Command Interpreter that turns text that you Command Interpreter that turns text that you

type (at the command line) in to actions:type (at the command line) in to actions: Shell is a process;Shell is a process; User Interface: take the command from userUser Interface: take the command from user

Page 5: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Flavors of Unix ShellsFlavors of Unix Shells

Two main flavors of Unix ShellsTwo main flavors of Unix Shells Bourne (or Standard Shell): sh, ksh, bash, zshBourne (or Standard Shell): sh, ksh, bash, zsh

• AT&T shellAT&T shell• FastFast• $ for command prompt$ for command prompt

C shell : csh, tcshC shell : csh, tcsh• Berkley ShellBerkley Shell• better for user customization and scriptingbetter for user customization and scripting• %, > for command prompt%, > for command prompt

To check shell:To check shell: % echo $SHELL (shell is a pre-defined variable)% echo $SHELL (shell is a pre-defined variable)

To switch shell:To switch shell: % exec shellname (e.g., % exec bash)% exec shellname (e.g., % exec bash)

Page 6: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Popular ShellsPopular Shells

shsh Bourne Shell Bourne Shell ksh ksh Korn Shell Korn Shell csh,tcshcsh,tcsh C Shell (for this course)C Shell (for this course) bash bash Bourne-Again Shell Bourne-Again Shell

Page 7: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Uses of ShellUses of Shell

Programming Shell can doProgramming Shell can do Interpret Commands: Parse, EvaluateInterpret Commands: Parse, Evaluate Customization of a Unix sessionCustomization of a Unix session Scripting: Interpreted Programming LanguageScripting: Interpreted Programming Language

Page 8: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Customization of a SessionCustomization of a Session

Each shell supports some customization.Each shell supports some customization. User promptUser prompt Where to find mailWhere to find mail Shortcuts (alias)Shortcuts (alias)

The customization takes place in The customization takes place in startupstartup files files Startup files are read by the shell when it Startup files are read by the shell when it

starts upstarts up The Startup files can differ for different shellThe Startup files can differ for different shell

Page 9: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Startup filesStartup files sh,ksh: sh,ksh:

/etc/profile (system defaults) /etc/profile (system defaults) ~/.profile~/.profile

bash:bash:

~/.bash_profile~/.bash_profile

~/.bashrc~/.bashrc

~/.bash_logout~/.bash_logout csh:csh:

~/.login: executed when you logon~/.login: executed when you logon ~/.cshrc: executed when a new shell is spawned~/.cshrc: executed when a new shell is spawned ~/.logout: executed at logout~/.logout: executed at logout

Page 10: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Running ModelRunning Model

User ModeUser Mode A process running in this mode can’t access A process running in this mode can’t access

kernel data structures and procedureskernel data structures and procedures Kernel ModeKernel Mode

A process running in this mode can access A process running in this mode can access kernel data structures and procedureskernel data structures and procedures

System callSystem call Can be looked as the interface between user Can be looked as the interface between user

mode and kernel modemode and kernel mode

Page 11: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Layout of address space Of A Process Layout of address space Of A Process (linux)(linux)

Page 12: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Creating ProcessesCreating Processes fork()fork()

Create a duplicate of the calling processCreate a duplicate of the calling process exec()exec()

Create a duplicate of the calling processCreate a duplicate of the calling process Load an executable program whose name is one of Load an executable program whose name is one of

arguments of exec() into the address space of the arguments of exec() into the address space of the new processnew process

wait()- wait()- Cause a parent process to sleep until one of Cause a parent process to sleep until one of its child processes terminatesits child processes terminates

exit()exit()

Page 13: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Your Best FriendYour Best Friend

% man command (e.g., % man ls)% man command (e.g., % man ls) shows information about the commandshows information about the command usually space or ↓ for more informationusually space or ↓ for more information q to quitq to quit % man man% man man

Page 14: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Some Common Commands ls –l mv src dst // rename a file rm file // delete files or directories cp src dst // copy files mail write sb // send an message to sb

lpr // print something wc file // word counting for a file tail –n file // print out the last n lines of file tail +n file // print out file starting from nth line mkdir dir_name // create a directory rmdir dir_name // delete a directory

Page 15: Welcome to CSE459.11  Name: Di Cao  Email: caod@cse.ohio-state.edu caod@cse.ohio-state.edu  Classroom: DL357  Class Time: T 8:30am - 9:18am  Office

Recommended ReadingRecommended Reading

Chapter 1, sections 1.1 – 1.5Chapter 1, sections 1.1 – 1.5