Introductions
- Participants
- Instructor: Prof. Brian D. Davison
- Students: undergraduates of varying majors/years
- Why take/teach this course?
Hey, very good -- printing these slides will help with studying, and
may include some comments like this that were not on the screen.
Topics and depth can (and likely will) be influenced by student
interest and abilities.
Course Objectives
- When this course is complete, you should
- Know how to program in the C programming language
- Be comfortable using UNIX
- Know how to use common C and UNIX development tools
- Be able to write UNIX shell scripts
- Be able to write moderate C programs utilizing common UNIX system
calls
Of course there is much more to the course, but these are the big items.
Course Structure
- Teaching
- Lectures, readings, labs (Wednesdays), homework
- Everything online
- Evaluation
- Two hourly exams (10%+10%), one final exam (20%),
programming (40%),
homework, weekly quizzes, class participation (20%)
Be certain to review the syllabus.
Homeworks and programming assignments will consist primarily of C
programs and UNIX shell scripts.
Course Materials
- Required Textbooks
- Harley Hahn's Guide to Unix and Linux, by Hahn (McGraw-Hill,
2009)
- Understanding Unix/Linux Programming: A Guide to
Theory and Practice, by Molay (Prentice Hall, 2003)
- Plus a book on C
- C Primer Plus, 5th Ed., by Prata (SAMS, 2005) RECOMMENDED
- C: A Reference Manual, 5th Ed., by Harbison and
Steele (Prentice Hall, 2002)
- Online Sources
- Many additional tutorials, textbooks, FAQs, etc.
- In-class Information
- You are responsible for everything we do in class.
Importance
- Why is UNIX important to know?
- Why is C important to know?
Solicit answers from class.
Why is UNIX important to know?
- Much of the Internet (routers, web servers, dns servers, etc.) runs
UNIX, and much of the original
Internet infrastructure was developed under UNIX
- Many UNIX apps and UNIX-like OSes are free and/or open source
- UNIX is
- An OS that is inherently multi-process and multi-user
- A powerful, scalable, efficient networked OS that runs on a variety of
hardware
- Often used in high-end workstations, supercomputers, and
government and large business computing centers
- Protected -- users can't access others' files, the death of one
process generally does not kill the machine, etc.
- An example of good software design tested by decades of use
- UNIX usually also includes the X-Window System, a powerful windowing
paradigm
How many different UNIX implementations can you name?
UNIX Maturation
- UNIX started out as an educational and research system
- UNIX (and UNIX-like OSes) have become a universal operating system
- Now found in
- embedded systems (parking meters, digital video recorders,
wristwatches, in-flight entertainment systems)
- Mac laptops and desktops
- almost all cell phones and tablets
- millions of web servers
- cheap desktop systems sold by Walmart, etc.
- It has grown much beyond its original design 30+ years ago
UNIX Philosophy
- Doug McIlroy
- Write programs that do one thing and do
it well
- Write programs to work together
- Write programs to handle text streams,
because that is a universal interface
- Unattributed
"The UNIX philosophy basically involves
giving you enough rope to hang yourself.
And then a couple of feet more, just to
be sure."
UNIX Philosophy, continued
- Use "filters" - small programs that do one
thing and can be combined with other small
programs
- Give users as much control as possible
without allowing them to affect other users
- Use common interfaces
- Devices, sockets, files all the same
- All data can be represented as character
sequences
- Simplicity is more important than
efficiency or featurism
UNIX Interfaces
- GUI or command line?
- GUI is great (easy) but often changes with later releases
- GUI requires graphics/mouse (obvious, but not always available)
- Every UNIX system has a command line interface
- The command line is (mostly) the same from version to version
- The command line can easily run multiple programs and be
scripted
Why is C important to know?
- UNIX was written in C, and most UNIX development is in C
- Sometimes called "easy to learn but difficult to master"
- C is programmer efficient -- code can be written briefly
- C is flexible and provides lots of developer control over
details, making it ideal when you need
operational speed and resource efficiency
- C code correlates highly with assembly,
making it easier to understand what is
really going on
- Many 'programmers' cannot program in C, making you more valuable.
:-)
- C code is usually faster than anything else
- Nearly everything offers a C library
The C Programming Language
- is weakly typed
- You can read data from memory as any type you like
- is staticly typed
- Types are only checked at compile-time
- is structured
- Structures are used to control the flow of execution (e.g., while,
for, if/then)
- is procedural
- C++ is mostly a superset of C that adds object oriented
functionality.
- is low-level
- C can directly access structures that are tied to hardware
History of C
-
The B language was created by Ken Thompson in 1969-1970, as a derivation
of BCPL.
- Dennis Ritchie turned B into C
during 1971-73, keeping most of B's syntax while adding types as well as
other changes.
- The (still new) UNIX OS was re-implemented in C in 1972-1974.
- Kernighan and Ritchie publish The C Programming Language,
defining the 'original' K&R C in 1978.
- Bjarne Stroustrup invents C++ in 1983-1985.
- ANSI C published in 1990.
- Revisions adopted in 1999 (ANSI C99).
The spirit of C
- The spirit of C (as summarized by a C standards committee):
- Trust the programmer.
- Don't prevent the programmer from doing what needs to be done.
- Keep the language small and simple.
- Provide only one way to do an operation.
- Make it fast, even if it is not guaranteed to be portable.
Homework
- Homework 0 is on the course website, and is due
Wednesday.
- Use ssh to log into a Sun.
- If you have forgotten your CSE/ECE Sun account password, or
don't yet have an account, send
mail to help (at) cse.lehigh.edu from your Lehigh account (e.g., via imp)
Demonstrate use of ssh.
Hello World
- Use an editor to create hello.c
- Compile using gcc hello.c
- Assuming no compilation or linking errors, run using
./a.out
- If no runtime errors, the program will output its greeting and
finish.
- In lab on Wednesday we will continue with:
- Using the X-Window system
- Intro to using UNIX