DOC PREVIEW
UW CSE 303 - Processes, Users, Shell Special Characters, Emacs

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 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 16 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 16 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 16 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 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

'&$%CSE 303:Concepts and Tools for Software DevelopmentDan GrossmanSpring 2007Lecture 2— Processes, Users, Shell Special Characters, EmacsDan Grossman CSE303 Spring 2007, Lecture 2 1'&$%Where are weIt’s like we starte d over using the c omputer from sc ratch.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:• Finish up lecture 1 (odds-and-ends plus shell-as-interpreter)• The rest of the model briefly: Processes and Users• More programs (ps, chmod, kill, ...)• Special shell characters (*, ~, ...)• Text e diting (particularly emacs)Dan Grossman CSE303 Spring 2007, Lecture 2 2'&$%More Lecture-1 Odds and Ends• man, cat, more, less• Key less/man commands: spacebar, b, /search-exp, q• exit• For file and directory operations (rm, cp, mv, ...), use man orPocket Guide pages 37–55 (or maybe 37–70)Note: Homework 1 is poste d, due April 6. You c an do the first 3 aftertoday (or 4 if you read about alias) and should do at least the firstcouple as soon as possible.Note: Bash reference manual in html linked from course webpage.Dan Grossman CSE303 Spring 2007, Lecture 2 3'&$%Lecture 1: How to think about the shellThe shell is an interpreter for a strange programming language (of thesame name). So far:• “Shell programs” are program names and arguments• The interpreter runs the program (passing it the arguments),prints any output, and prints another prompt. The program canaffect the file-system, send mail, open windows, etc.• “Builtins” such as exit and cd give directions to the interpre ter.It’s actually much more c omplicated:• (two kinds of) variables.• some programming constructs (conditionals, loops, etc.)• The shell interprets lots of funny characters differently, rather thanpass them as options to programs.Dan Grossman CSE303 Spring 2007, Lecture 2 4'&$%Users• There is one file-system, one operating system, (often) one CPU,and multiple users.• whoami• ls -l and chmod (permissions), quota (limits)– Make your homework unreadable by others!• /etc/passwd guides the login program:– Correct username and password– Home directory– Which shell to open (pass it the home directory)– The shell then takes ove r, with startup scripts (e.g.,.bash login). (ls -a)• one “superuser” a.k.a. root. (Change passwords, halt machine, ...)Dan Grossman CSE303 Spring 2007, Lecture 2 5'&$%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– ps, top• A running shell is just a process that kills itself when interpretingthe exit command.• (Apologies for aggressive vocabulary, but we’re stuck with it fornow.)Dan Grossman CSE303 Spring 2007, Lecture 2 6'&$%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...Dan Grossman CSE303 Spring 2007, Lecture 2 7'&$%Complicating the shellSo far, our view of the shell is the 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.Dan Grossman CSE303 Spring 2007, Lecture 2 8'&$%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 itse lf) – 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.Dan Grossman CSE303 Spring 2007, Lecture 2 9'&$%Filename metacharacters: why• Manually, you use them all the time to save typing.• In scripts, you use them for flex ibility. 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 esc aping(\*).The rules on what needs escaping where are very arcane.Dan Grossman CSE303 Spring 2007, Lecture 2 10'&$%Where are weFeatures of the bash “language”:1. builtins2. program execution3. filename expansion (Pocket Guide 22–23)4. command-line editing and history5. shell and environment variables6. programming constructsBut file editing is too useful to put off... so a detour to emacs (whichshares some editing commands with bash)Dan Grossman CSE303 Spring 2007, Lecture 2 11'&$%What is emacs?A programmable, extensible text e ditor, 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, ...Customizable with elisp (starting with your .emacs).Dan Grossman CSE303 Spring 2007, Lecture 2 12'&$%Putting it all together: JavaJava is a programming language; you can write and run programs invarious environments.The javac and java programs “compile” and “run” Java programsand emacs has a decent Java mode.So we c an write Java files in emacs, and use the shell to run theprogram and pass arguments.(The Java program takes the class whose main should be run as itsfirst argument and gives it the re maining arguments.)Dan Grossman CSE303 Spring 2007, Lecture 2 13'&$%History• The history builtin• The ! special character– !!, !n, !abc, ...– Can add,


View Full Document

UW CSE 303 - Processes, Users, Shell Special Characters, Emacs

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Processes, Users, Shell Special Characters, Emacs
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 Processes, Users, Shell Special Characters, Emacs 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 Processes, Users, Shell Special Characters, Emacs 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?