DOC PREVIEW
UW CSE 303 - Lecture Notes

This preview shows page 1-2-3-4-5-6 out of 17 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 17 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

'&$%CSE 303:Concepts and Tools for Software DevelopmentHal PerkinsAutumn 2008Lecture 2— Processes, Users, Shell Special Characters, EmacsCSE303 Autumn 2008, Lecture 2 1'&$%Where are weIt’s like we started over using the computer from scratch.And all we can do is run dinky programs at the command-line.But we are learning a model (the system is files, processes, and users)and a powerful way to control it (the shell).If we get the model right, hopefully we can learn lots of details quickly.Today:• The rest of the model briefly: Processes and Users• More programs (ps, chmod, kill, ...)• Special shell characters (*, ~, ...)• Text editing (particularly emacs)CSE303 Autumn 2008, Lecture 2 2'&$%Announcements &c.• For file and directory operations (rm, cp, mv, ...), use man orPocket Guide pages 37–55 (or maybe 37–70)• Homework 1A is due Monday night. You can do it after today.• Homework 1B (basic shell scripting) will be posted shortly. We’lltalk about scripting next week.• Bash reference manual in html linked from course webpage, or useinfo bash from the shell.• Instructor office hours: Mon. 4:45-5:30, Tue. 2:00-3:00; CSE548.• Email request 1: If you send em ail to your instructor, please put“303” somewhere in the subject heading.• Email request 2: Your instructor is outnumbere d and can’t(successfully) serve as a 24/7 email help desk. Take advantage ofthe discussion board and other resources if you can.CSE303 Autumn 2008, Lecture 2 3'&$%Users• There is one file-system, one operating system, one or more CPUs,and multiple users.• whoami• ls -l and chmod (permissions), quota (limits)– Make your homework unreadable by others!• /etc/passwd (or e quivalent) guides the login program:– Correct username and password– Home directory– Which shell to open (pass it the home direct ory)– The shell then takes over, with startup scripts (e.g.,.bash login). (ls -a)• one “superuser” a.k.a. root. (Change passwords, halt machine, ...)CSE303 Autumn 2008, Lecture 2 4'&$%Processes• A running program is called a process. An application (e.g.,emacs), may be running as 0, 1, or 57 processes at any time.• The shell runs a program by “launching a process” waiting for itto finish, and giving you your prompt back.– What you want for ls, but not for emacs.– &, jobs, fg, bg, kill — job control– ps, top• A running shell is just a process that kills itself when interpretingthe exit command.• (Apologies for aggressive vocabulary, but we’re s tuck with it fornow.)CSE303 Autumn 2008, Lecture 2 5'&$%That’s most of a running system• File-system, users, processes• The operating system manages these• Processes can do I/O, change files, launch other processes.• Other things: Input/Output devices (monitor, keyboard, network)• GUIs don’t change any of this, but they do hide it a bit.Now: Back to the shell...CSE303 Autumn 2008, Lecture 2 6'&$%Complicating the shellSo far, our view of the shell is t he barest minimum:• builtins affect subsequent interpretations. New: source• Otherwise, the first “word” is a program run with the other“words” passed as arguments.– Programs interpret arguments arbitrarily, but conventions exist.But you want (and bash has) so much more:• Filename metacharacters• Pipes and Redirections (redirecting I/O from and to files)• Command-line editing and history access• Shell and environment variables• Programming Constructs (ifs, loops, arrays, expressions, ...)All together, a very powerful feature set, but awfully unelegant.CSE303 Autumn 2008, Lecture 2 7'&$%Filename metacharactersMuch happens to a command-line to turn it into a “call program witharguments” (or “invoke builtin”).Certain characters can expand into (potentially) multiple filenames:• ~foo – home directory of user foo• ~ – current user’s home directory (same as ~$user or‘whoami‘).• * (by its elf) – all files in current directory• * – match 0 or more filename characters• ? – match 1 filename character• [abc], [a-E], [^a], ... more matchingRemember, this happens before deciding what to pass to a program.CSE303 Autumn 2008, Lecture 2 8'&$%Filename metacharacters: why• Manually, you use them all the time to save typing.• In scripts, you use t hem for flexibility. Example: You do not knowwhat files will be in a directory, but you can still do: cat *(though a better script would skip directories).But what if it’s not what you want? Use quoting ("*") or e sc aping(\*).The rules on what needs escaping where are very arcane.A way to experiment: echo• echo args. . . copies its arguments to standard output afterexpanding metacharacters.CSE303 Autumn 2008, Lecture 2 9'&$%History• The history builtin• The ! spec ial character– !!, !n, !abc, ...– Can add, substitute, etc.This is really for fast manual use; not so useful in scripts.CSE303 Autumn 2008, Lecture 2 10'&$%AliasesIdea: Define a new command that expands to something else (not afull script)• alias repeat=echo• alias hello="echo hello"• alias rm="rm -i" % for cautious usersOften put in a file read by source or in a startup file readautomatically.CSE303 Autumn 2008, Lecture 2 11'&$%Where are weFeatures of the bash “language”:1. builtins2. program execution3. filename expansion (Pocket Guide 22–23)4. history & aliases5. command-line editing6. shell and environment variables7. programming constructsBut file editing is too useful to put off... so a detour to emacs (whichshares some editing commands with bash)CSE303 Autumn 2008, Lecture 2 12'&$%What is emacs?A programmable, extensible text editor, with lots of goodies forprogrammers.Not a full-blown IDE. Much “heavier weight” than vi.Top-6 commands:• C-g• C-x C-f• C-x C-s, C-x C-w• C-x C-c• C-x b• C-k, C-w, C-y, ...Take the emacs tutorial to get the hang of the basics.Customizable with elisp (starting with your .emacs).CSE303 Autumn 2008, Lecture 2 13'&$%Command-line editingLots of control-characters for moving around and editing thecommand-line. (Pocket Guide page 28, emacs-help, and Bashreference manual Section 8.4.)They make no se nse in scripts.Gotcha: C-s is a strange one (stops displaying output until C-q, butinput does get executed).Good news: many of the control characters have the same meaning inemacs (and bash has a vi “mode” too).CSE303 Autumn 2008, Lecture 2 14'&$%Bash startup filesBash reads (sources) specific files w hen it starts up. Put


View Full Document

UW CSE 303 - Lecture Notes

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?