Advanced Programming in the UNIX Environment
CS631 - APUE
Course Outline
In this course, students will learn to develop complex
system-level software in the C programming language while gaining
an intimate understanding of the Unix operating system (and
all OS that belong to this family, such as Linux, the BSDs, and
even Mac OS X) and its programming environment.
Topics covered will include the user/kernel
interface, fundamental concepts of Unix, user
authentication, basic and advanced I/O, fileystems, signals,
process relationships, and interprocess communication.
Fundamental concepts of software development and
maintenance on Unix systems (development and debugging
tools such as "make" and "gdb") will also be covered.
Students are expected to have a good working knowledge
of the C programming language, have written non-trivial
programs before, and to be able to competently use a Unix
system with a command-line shell interface.
All coursework will be done exclusively on a Unix system
from the command-line. All programming is done in C. This is not an
introduction to using Unix nor to programming in C!
If you email me to waive the prerequisites, please provide
information about how you meet the requirements listed above in
bold. (This has the added benefit of showing that you've actually
read at least this far on this page.)
Time, Date & Place:
Interactive/synchronous: Mondays, 18:30 Eastern, Babbio 202
Online on-demand: anytime via YouTube video
lectures
Instructor:
Jan Schaumann
[[email protected]]
Office Hours: by appointment Mondays, 18:00 Eastern
When emailing me, please use your @stevens.edu address.
I will likely not even see your email if it is sent from gmail
or any other non-stevens address.
Resources:
Content and discussions:
Assignments and meta-information:
Related links and documents:
Tool Tips:
Source Code
You will be writing a lot of code in this class. You may
also find the need to read a lot of code not written by you
as well as the manual pages accompanying the sources.
Our primary reference platform being
NetBSD, you can install the full sources into
your VirtualBox or
UTM VM via e.g., this script.
To browse or fetch sources for other Open
Source Unix variations, please see these
links:
Textbooks:
The textbook used in this class is:
The following books are recommended purely for your own personal
reference. They're not used in the class as a text, but are
related and very useful books to have:
-
``The C
Programming Language'' -- important: make
sure you get the 2nd Edition covering
ANSI C.
by Brian W. Kernighan and Dennis M. Ritchie.
Prentice Hall, Inc., 1988.
ISBN 0-13-110362-8 (paperback), 0-13-110370-9
(hardback).
-
``The Practice of
Programming''
by Brian W. Kernighan and Rob Pike.
Addison-Wesley, Inc., 1999.
ISBN 0-201-61586-X.
In addition, please consider MIT's "Missing
Semester" a course pre- or co-requisite:
Systems Used
All software development will be done on a NetBSD system. It is
your responsibility to gain access to such a system prior
to the start of the class. Please see this
page for more information. Here are instructions on how to install NetBSD in a VirtualBox or UTM.
All grading will be done on a NetBSD >= 10.0 system. While you may
choose to develop on your own personal host, you should make sure
that your code compiles and runs flawlessly on this OS version.
Grading:There will most likely be:
- participation and checkpoints: 50 points
- 2 homework assignment, worth 25 points each
- 1 midterm project, worth 100 points
- 1 group project, worth 200 points
- 1 final assignment, worth 100 points
- no make-up assignments
- no extra credit
- no curve
Letter grades will be given as follows:
- 90% - 100% of total available points => A
- 80% - 90% of total available points => B
- 70% - 80% of total available points => C
- 0 - 70% of total available points => F
Within each letter grade, there are +/- grades given at the
discretion of the instructor. (Exception: there is no A+)
Plagiarism, Cheating and other ways to get an F
This really should not be necessary, but just to preempt any complains
that I did not make myself clear:
Students are responsible for their own work. It is unethical (and in
some cases illegal) to present as one's work the ideas, words or
representations of another without the proper indication of the
source. Therefore, it is the student's responsibility to give credit
for any quotation, idea or data (such as statistical data or source
code) borrowed from an outside source.
Failure to do so constitutes plagiarism, may imply copyright
infringement and license violations and is viewed as cheating
in this class.
Any incidents are reported to the Dean of Graduate
Academics, as per the Graduate
Student Code of Academic Conduct.
Note: this also applies to the use of AI such
as (but not limited to) e.g., ChatGPT. Please
see this document
for more details on the permitted use of AI in this
class.
Homework Assignments:
Assignments will be posted as the semester progresses.
The following exercises are not graded, but
are recommended to be completed before or soon after
the given lecture to help you better understand the
concepts dicussed.
Midterm Project:
Implement the "ls(1)" command as
decribed in the manual page provided to you.
See the full midterm project
description for details.
Group Project:
Implement the "sws(1)" command as
decribed in the manual page provided to you.
See the full group project
description for details.
Syllabus:
Homework assignments, slides, and other material listed below are
from the previous semester. We will update the content as the
semester progresses.
Date |
Topic |
Reading |
Links |
2024-09-09 |
Introduction, UNIX history, UNIX Programming
Basics |
Stevens: Chapters 1, 2
Unix history and basic features |
Week 01, Segment 1: Introduction
[slides] [video lecture] [transcript]
Week 01, Segment 2: UNIX History
[slides] [video lecture] [transcript]
Week 01, Segment 3: UNIX Basics
[slides] [video lecture] [transcript]
simple-cat.c
simple-ls.c
simple-shell.c
simple-shell2.c
welcome.c
Week 01 Checkpoint (due by 16:00 Eastern before class)
|
2024-09-16 |
File I/O, File Sharing |
Stevens: Chapter 3 |
Week 02, Segment 1: File Descriptors
[slides] [video lecture] [transcript]
Week 02, Segment 2: open(2)/close(2)
[slides] [video lecture] [transcript]
Week 02, Segment 3: read(2)/write(2)/lseek(2)
[slides] [video lecture] [transcript]
Week 02, Segment 4: File Sharing
[slides] [video lecture] [transcript]
argv.c
close-stderr.c
fds.c
hole.c
lseek.c
openat.c
openex.c
openmax.c
redir.c
rwex.c
sync-cat.c
Week 02 Checkpoint (due by 16:00 Eastern before class)
HW1: bbcp(1)
|
2024-09-23 |
Files and Directories |
Stevens: Chapter 4 |
Week 03, Segment 1: stat(2) intro
[slides] [video lecture] [transcript]
Week 03, Segment 2: UIDs intro
[slides] [video lecture] [transcript]
Week 03, Segment 3: struct stat st_mode
[slides] [video lecture] [transcript]
Week 03, Segment 4: chmod(2) and chown(2)
[slides] [video lecture] [transcript]
Week 03, Segment 5: umask(2)
[slides] [video lecture] [transcript]
Week 03, Segment 6: Union Mounts and Whiteout Files
[slides] [video lecture] [transcript]
access.c
chmod.c
chown.c
myuids.c
setuid.c
size.c
simple-ls.c
simple-ls-stat.c
umask.c
Week 03 Checkpoint (due by 16:00 Eastern before class)
Midterm Project Assignment |
2024-09-30 |
Filesystems, System Data Files, Time &
Date |
Stevens: Chapter 4, 6
File Systems and Storage Models: 4.4.1, 4.5 - 4.7 |
Week 04, Segment 1: The Unix Filesystem
[slides] [video lecture] [transcript]
Week 04, Segment 2: Links
[slides] [video lecture] [transcript]
Week 04, Segment 3: Directories
[slides] [video lecture] [transcript]
Week 04, Segment 4: Directory Size
[slides] [video lecture] [transcript]
Week 04, Segment 5: /etc/passwd
[slides] [video lecture] [transcript]
Week 04, Segment 6: getpwuid(2) and /etc/groups
[slides] [video lecture] [transcript]
Week 04, Segment 7: atime, mtime, ctime
[slides] [video lecture] [transcript]
Week 04, Segment 8: time(3) is an illusion
[slides] [video lecture] [transcript]
cd.c
getpw.c
groups.c
lns.c
rename.c
sizeof.c
time.c
wait-unlink.c
Week 04 Checkpoint (due by 16:00 Eastern before class)
|
2024-10-07 |
UNIX tools: cc(1), make(1), revision control, diff(1), patch(1), gdb(1) |
CVS Documentation
Mini FAQ
about the misc libc/gcc crt files
Debugging with GDB
Guide to Faster, Less Frustrating Debugging
gdb
Tutorial
Git |
Week 05, Segment 1: The Unix Development Environment
[slides] [video lecture] [transcript]
Week 05, Segment 2: The Editor
[slides] [video lecture] [transcript]
Week 05, Segment 3: The Compiler Toolchain, Part I
[slides] [video lecture] [transcript]
Week 05, Segment 4: The Compiler Toolchain, Part II
[slides] [video lecture] [transcript]
Week 05, Segment 5: The Compiler Toolchain, Part III
[slides] [video lecture] [transcript]
Week 05, Segment 6: The Compiler Toolchain, Part IV
[slides] [video lecture] [transcript]
Week 05, Segment 7: make(1)
[slides] [video lecture] [transcript]
Week 05, Segment 8: Debugging Your Code
[slides] [video lecture] [transcript]
Week 05, Segment 9: Using gdb(1)
[slides] [video lecture] [transcript]
Week 05, Segment 10: Using gdb(1), part II
[slides] [video lecture] [transcript]
Week 05, Segment 11: Using gdb(1), part III
[slides] [video lecture] [transcript]
Week 05, Segment 12: Using gdb(1) to understand pointers
[slides] [video lecture] [transcript]
Lecture Slides
compile chain examples
make examples
gdb examples
Week 05 Checkpoint (due by 16:00 Eastern before class)
|
2024-10-14 |
Fall Recess |
2024-10-15 |
Process Environment, Process Control |
Note: Tuesday Class
Stevens: Chapters 7, 8
Smashing The Stack For Fun And Profit
Linux x86 Program Start Up
stdarg And The Case Of The Forgotten Registers
There is no 'printf'.
Process Creation |
Week 06, Segment 1: Memory Layout of a Process
[slides] [video lecture] [transcript]
Week 06, Segment 2: Program Startup
[slides] [video lecture] [transcript]
Week 06, Segment 3: Program Termination
[slides] [video lecture] [transcript]
Week 06, Segment 4: The Environment
[slides] [video lecture] [transcript]
Week 06, Segment 5: Process Limits and Identifiers
[slides] [video lecture] [transcript]
Week 06, Segment 6: Process Control
[slides] [video lecture] [transcript]
const.c
entry.c
exit-handlers.c
forkflush.c
forkseek.c
hw.c
malloc.c
memory-layout0.c
memory-layout1.c
memory-layout2.c
memory-layout3.c
memory-layout4.c
memory-layout5.c
memory-layout6.c
memory-layout7.c
memory-layout8.c
sum.c
zombies.c
NetBSD crt0-common.c
Week 06 Checkpoint (due by 16:00 Eastern before class)
|
2024-10-21 |
Process Groups, Sessions, Signals |
Stevens: Chapter 9, 10
POSIX
Terminal Interface Description
Shichao's Notes
FreeBSD Process Management (from "The Design and Implementation of the FreeBSD Operating System")
Delivering Signals for Fun and Profit |
Week 07, Segment 1: The Login Process
[slides] [video lecture] [transcript]
Week 07, Segment 2: Process Groups and Sessions
[slides] [video lecture] [transcript]
Week 07, Segment 3: Job Control
[slides] [video lecture] [transcript]
Week 07, Segment 4: Signals
[slides] [video lecture] [transcript]
Week 07, Segment 5: Reentrant and Interrupted Functions
[slides] [video lecture] [transcript]
eintr.c
pending.c
reentrant.c
signals1.c
signals2.c
signals3.c
signals4.c
sigusr.c
Week 07 Checkpoint (due by 16:00 Eastern before class)
|
2024-10-28 |
Interprocess Communication I |
Stevens: Chapter 15
Shared Memory Introduction
Semaphores in Linux
Interprocess communication using POSIX message queues in Linux
POSIX Message Queues
|
Week 08, Segment 1: Interprocess Communications Intro
[slides] [video lecture] [transcript]
Week 08, Segment 2: System V IPC
[slides] [video lecture] [transcript]
Week 08, Segment 3: Pipes and FIFOs
[slides] [video lecture] [transcript]
BSD IPC Tutorial
Beej's Guide to Unix IPC
memory-layout.c
mqrecv.c
mqsend.c
msgrecv.c
msgsend.c
pipe1.c
pipe2.c
popen.c
semdemo.c
shmdemo.c
Week 08 Checkpoint (due by 16:00 Eastern before class)
HW#2: implement 'command(3)'
|
2024-11-04 |
Interprocess Communication II |
Stevens: Chapter 16 / 17
BSD IPC
How Linux creates sockets and counts them
How Linux allows TCP introspection
The C10K problem
IPC Buffer Sizes
|
Week 09, Segment 1: socketpair(2)
[slides] [video lecture] [transcript]
Week 09, Segment 2: socket(PF_LOCAL, SOCK_DGRAM, 0)
[slides] [video lecture] [transcript]
Week 09, Segment 3: socket(PF_INET, SOCK_DGRAM, 0)
[slides] [video lecture] [transcript]
Week 09, Segment 4: socket(PF_INET6, SOCK_STREAM, 0)
[slides] [video lecture] [transcript]
Week 09, Segment 5: I/O Multiplexing
[slides] [video lecture] [transcript]
dualstack-streamread.c
socketpair.c
udgramread.c
udgramsend.c
dgramread.c
dgramsend.c
streamread.c
streamwrite.c
two-sockets.c
two-sockets-select.c
one-socket-select.c
one-socket-select-fork.c
Week 09 Checkpoint (due by 16:00 Eastern before class)
Group Project Assignment
|
2024-11-11 |
Dæmon Processes, HTTP / Group Project Discussions |
Stevens: Chapter 13
|
Week 10, Segment 1: Dæmon Processes
[slides] [video lecture] [transcript]
HTTP Slides |
2024-11-18 |
Shared Libraries |
How to read an Executable
Ian Lance Taylor's blog post series on linkers
Linkers and Loaders
How To Write Shared Libraries
Tool Interface Standard (TIS) ELF Specification
GNU indirect function support (IFUNC)
The Executable and Linkable Format (ELF) |
Week 11, Segment 1: The Executable and Linkable Format
[slides] [video lecture] [transcript]
Week 11, Segment 2: Of Linkers and Loaders
[slides] [video lecture] [transcript]
Week 11, Segment 3: Shared Libraries
[slides] [video lecture] [transcript]
crypt.c
dlopenex.c
evil.c
hello.c
ldtest1.2.c
ldtest1.c
ldtest2.c
main.c
setget.c
Week 11 Checkpoint (due by 16:00 Eastern before class)
libgreet exercise |
2024-11-25 |
Advanced I/O: Nonblocking I/O, Polling, and Record
Locking / Encryption in a Nutshell |
Stevens: Chapter 14 |
Week 12, Segment 1: syslog(3)
[slides] [video lecture] [transcript]
Week 12, Segment 2: Non-blocking I/O
[slides] [video lecture] [transcript]
Week 12, Segment 3: Resource Locking
[slides] [video lecture] [transcript]
Week 12, Segment 4: Asynchronous and Memory Mapped I/O
[slides] [video lecture] [transcript]
Lecture
Slides (previous semester, includes section on
encryption basics)
slogdemo.c
nonblock.c
flock.c
Use strlcat(3)!
Week 12 Checkpoint (due by 16:00 Eastern before class)
|
2024-12-02 |
Restricting processes / Containers |
Course Notes
Thread
scheduling and related interfaces in NetBSD 5.0
CPU Pinning and CPU Sets |
Week 13, Segment 1: POSIX ACLs
[slides] [video lecture] [transcript]
Week 13, Segment 2: eUIDs, file flags, mount options, securelevels
[slides] [video lecture] [transcript]
Week 13, Segment 3: Restricted shells, Chroots, Jails
[slides] [video lecture] [transcript]
Week 13, Segment 4: Process Priorities
[slides] [video lecture] [transcript]
Week 13, Segment 5: Processor Affinity and CPU Sets
[slides] [video lecture] [transcript]
Week 13, Segment 6: Capabilities, Control Groups, Containers
[slides] [video lecture] [transcript]
break-chroot.c
busy-child.c
load.c
priority.c
mkchroot
Week 13 Checkpoint (due by 16:00 Eastern before class)
|
2024-12-09 |
Review |
|
Review Slides
Final Assignment: sish(1)
Week 14 Checkpoint (due by 16:00 Eastern before class)
|
|