CSE271: Programming in C and the UNIX Environment
Introduction
Prof. Brian D. Davison
Computer Science & Engineering, Lehigh University
Introductions
- Participants
- Instructor: Prof. Brian D. Davison
- TA: Osama Khan
- Class: about 20 students 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, 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
- Programming in C, 3rd ed., by Kochan
- Understanding Unix/Linux Programming: A Guide to
Theory and Practice, by Molay
- Recommended Textbooks
- UNIX Shells By Example, 4th ed., by Quigley
- 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 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
- It is an OS that is inherently multi-process and multi-user
- Powerful, scalable, efficient networked OS that runs on a variety of
hardware
- Often used in high-end workstations and supercomputers
- Protected -- users can't access others' files, the death of one
process generally does not kill the machine, etc.
- Usually includes X-Windows, 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, PDAs)
- inside Macintoshes
- millions of web servers
- cheap desktop systems sold by Walmart
- It has grown much beyond its original design 30+ years ago
UNIX Interfaces
- GUI or command line?
- GUI is great (easy) but often changes
- 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 gives control over details, making it ideal when you need
operational speed and resource efficiency
- Often if you understand C, you understand how the system
really works.
- Many 'programmers' cannot program in C. :-)
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.
- Lehigh students can get a number of ssh-compatible implementations
here for
various operating systems.
- 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
Demonstrate use of ssh.
Hello World
- Use an editor to create hello.c
- Compile using gcc hello.c
- Assuming no errors, run using ./a.out
- If no errors, the program will output its greeting and finish.
- Next class we will continue with:
- The development process
- Editing with emacs
- UNIX commands