csci 243: c & unix kirk anne south 124a [email protected]
Post on 20-Dec-2015
225 views
TRANSCRIPT
Course Description
• 5 weeks
• Teach you how to use UNIX
• Teach you how to program in C
• Practical, not theoretical
• “Tricks of the trade”
• How to not spend hours in front of the computer
Grading
• The only way to learn C is to program.
• Programs will be graded on:– Correctness– Style– Spelling
• Programs must produce correct answers.
• If errors, programs should exit gracefully.
Projects
• Syllabus tells you what you need for a “C”.– Three programs by end of week 2.– Three programs by end of week 3.– Three programs by end of week 4.– One program and final project, end of week 5.
• Final project– Can be from another class to save time
Final Project
• You can use a project from another class
• Or…– Write a library of functions for a stack and a
“reverse Polish notation” calculator (HP)– Write a “substantial program”
Tentative Schedule
• Week 1: Intro• Week 2: Basic C• Week 3: Structures• Week 4: Pointers• Week 5: Shell Scripts
• Editors, X windows• Control statements• Functions• Debugging, profiling• Course Wrapup
Plagiarism
• The exercises are published on the Internet.
• I know this.
• This class may be your only chance to practice C with the “safety net”.
• This is where you will learn how C works.
• Cheating will only hurt you.
History of UNIX
• 1969…– The Year of Woodstock– Armstrong walks on the moon– The Year of “Space Travel”– A PDP-7 sits in a corner of a lab…
• 9K of RAM
• Paper tape drive
• Teletype 33 terminal
A plan comes together...
• Dennis Ritchie and Ken Thompson take a PDP-7 and use their research at AT&T to produce the first computer that can play “Space Travel”.
• Based on research from GE, MIT and AT&T called Multics, a powerful operating system, UNIX is born.
• But much simpler...
Multics
• Multiplexed Information & Computing Service
• Too big to work but had…– Interactivity– Shared Physical and Virtual Memory– Symmetric Multiprocessing– Security– Software Engineering– Hierarchical File Storage System– Programmed in PL/I
UNIX
• Took a lot of Multics ideas
• But reduced the complexity
• Originally written in assembly
• Uses a “layered” approach to achieve complexity
What’s “C” got to do with it?
• C is derived from BCPL, another language available on Multics.
• C is a “middle level” language.– Low level - Assembly (fast but only one CPU)– High level - FORTRAN, PL/I (slow, but easy)
• C allows you the power of assembly with the ease of a high level language.
C makes UNIX portable
• Kernighan & Ritchie write a C compiler to prepare code for the PDP-7 UNIX project.
• Made C small and easy to port.
• When they got a PDP-11 with 24K, it ported quickly.
• After converting the UNIX system from assembly to C, it ported quickly too.
UNIX becomes popular
• Once a C compiler is written for a new CPU, the UNIX operating system can be ported soon after.
• AT&T couldn’t sell UNIX because the gov’t said that their phone monopoly was enough.
• They gave it away to universities...
UNIX meets Berkeley...
• CS graduate students got their hands on the source code for an entire operating system.
• The prices for PDP-8s and PDP-11s enabled research universities to allow grad students to work on their “own”computers.
• UC Berkeley graduates take the source and run...
BSD UNIX
• Bill Joy (one of the founders of Sun Microsystems), leads the CSRG to build a new version of UNIX called Berkeley Software Disitribution (BSD).
• SUN actually stands for Stanford University Network.
CSRG products
• “vi” (vee-eye)
• sendmail
• lint
• make
• TCP/IP (Internet)
• telnet, ftp, rlogin, rsh, rcp, etc…
The “Tower of Babel”
• AT&T invents UNIX
• Berkeley reinvents UNIX as BSD UNIX
• Corporations realize it’s cheaper to use UNIX
• Everybody has a version of UNIX
• Two major types– AT&T System V and BSD
Corporate UNIX
• In the early 1990’s, corporations wanted to have a “corporate UNIX” that conformed to standards.
• The Open Software Foundation was formed to create a “standard UNIX”.
• AT&T wanted to keep the UNIX name.
What goes around, comes around
• AT&T joined forces w/ Sun (Bill Joy,BSD) to create the UNIX Software Labs and System V Release 4 (SVR4).
• Sun drops development on its BSD system
• Solaris is born...
“Buzz Word” Compliant
• Multiuser– more than one person can use the system
• Multitasking– more than one job can be done at a time
• Hierarchical– Different levels, resembling an upside-down
tree
File System
/b inU tilit ies
/e tcS ys tem files
/liblib ra ries
/u s r/b in /u s r/lib /u s r/s rc
/u s r/loca l/b in /u s r/loca l/ lib /u s r/loca l/s rc
/u s r/loca lL oca l p rog ram s
/u s rU ser P rog ram s
/h om eU ser F iles
/(roo t d irec to ry)
Basic UNIX commands
• date• ls• cat file• mv old new• cp original new• rm file• more file• pwd
• See what time it is• List directory• Display a file• Move a file (rename)• Copy a file• Remove a file• Page through a file• Print working directory
UNIX Files
• One of the strengths of UNIX is that a “file” is just considered a stream of information with a starting point and an optional length.
• UNIX can treat almost anything as a file.
• Because of this, handling data is very easy.
Directories
• A directory is a special type of file that holds information about other files.
• Can be used to store similar files– mkdir Make a directory– cd Change directory– rmdir Remove an empty directory– ls List a directory
Wildcards and“Regular Expressions”
• A star “*” indicates all files that match.
• A question mark “?” means just one character.
• Brackets can restrict which letters are used.– [A-Z] All upper case letters– *[02468] All files that end w/even numbers– [aeiou]* All files that start w/vowels