System Programming
CMPT 242, Spring 2018
Google classroom: 3wclclu
The course introduces software techniques in a Unix-style environment, using scripting languages and a machine-oriented programming language (typically C). By the end of the course students should be able to use existing and create new software tools, implement forks and pipes, signals and sockets, and feel comfortable with shell scripting.
Table of contents |
---|
1. Course Info
1.1. Contacts |
|
---|---|
Instructor: | Marina Barsky |
Lecture hours: | TR, 12:35 - 2:00 PM, FSH 102 |
Office hours (Tentative): | R, 6:40 - 7:40 PM, FSH 111 |
e-mail: | [email protected] |
1.2. Textbooks
- "C Programming: A Modern Approach" by K.N. King, W. W. Norton et. al., 2008.
Note: This is a particularly good book for learning C. Online resources are not as good or plentiful as they are for other languages. -
"The Linux Programming Interface" by Michael Kerrisk, 2010.
This book is recommended. Some students like to have the additional resource for the systems programming part of the course, and other get by fine without it. This book won’t be used until about halfway through the course.
1.3. Deliverables |
|||
---|---|---|---|
Weekly preparation | 5% | (at-home) | |
Weekly exercises | 10% | (in-class) | |
Weekly labs | 15% | (at-home) | |
3 programming assignments | 30% | (at-home) | |
Midterm exam | 10% | March 1 | |
Final exam*: | 30% | Scheduled by the college |
*Score of at least 50% is required in order to pass the course.
2. Lecture handouts
- Course mechanics
- Intro to Linux.
Linux operating system. File system. Permissions. Basic commands. I/O redirection.
Piping. Slides 01.01. All you need to master: List of commands.
Input files: months,
days,
faculty,
A,
B.
Scripts of training sessions: diff, comm - session 1, sort, uniq, grep - session 2, set operators - session 3.
Exercises: Permissions and set operators.
Readings (optional): A Practical Guide to Linux Commands by M. Sobell: Chapters 1-5. - Writing Linux tools. Writing small C programs. Slides 02.01.
Standard input, standard output, standard error. I/O redirection and piping. Slides 02.02.
Input files: walk.csv, walk1.csv,
events.csv. Starter code: geo2js.c,
bermuda.c. Result demo: mywalk.html,
bermuda.html.
If you want to see the html on Windows machine, download pscp.exe, stick it into your path, and do secure copy from cmd:pscp [email protected]:w1/* .
- Pointers and arrays.
Memory addresses. Pointers. Difference between an array and a pointer. Pointer decay. Slides 03.01.
Exercises: Pointer exercises.
Readings: King: Chapters 11-12. - C memory model. Heap and stack. Memory allocation on the heap. Freeing dynamic memory. Slides 03.02.
Constants. String literals. Char array vs. char pointer. Slides 03.03.
Exercises: Memory exercises.
Readings: King: Chapter 13 and Sections 17.1 - 17.4. - Structs and linked structures. User-defined data types. Structs and pointers to structs.
Slides 03.04.
Linked lists. Slides 03.05.
Exercises: Linked list exercises.
Readings: King: Chapter 16 and Section 17.5. - Memory safety. Large programs. Memory corruption: detect and fix. Golden rules of C programming.
Slides 04.01. Writing large programs. C compilation model. Automating builds with
make.
Slides 04.02.
Readings: King: Chapter 15, Section 17.7. - Processes and forks. System calls. Forking new processes.
Slides 05.01.
Wait. Slides 05.02.
Exercises: Fork exercises.
Readings: Kerrisk: 2.6, 2.7, 24.1. - Pipes. File descriptors. Half-duplex inter-process communication with pipes.
Slides 06.01.
Readings: Kerrisk: 43.1, 44.1 - 44.2. - Signals. Sending signals to processes. Overriding signal handlers.
Slides 07.01.
Exercises: Signal exercises.
Readings: Kerrisk 63.1 and 63.2.1. - Sockets. Full-duplex communication between unrelated processes. Unix domain sockets.
Slides 08.01.
Challenges of Internet sockets: endianness, end-of-line and partial reads. Slides 08.02.
Internet sockets. Host and port. Handling multiple clients with select.
Slides 08.03.
Readings: Kerrisk 56.1 - 56.5. - Advanced C. Function pointers. "Objects". Sorting with qsort. Slides 09.01. Sample code. Bitwise operators. Slides 10.01.
3. Labs
Weekly online labs
- Lab 1. Linux tools in C. Euclidean distance. https://src-code.simons-rock.edu/git/mbarsky/eucl_distance_tools.git. Self-test. Due: Saturday, February 3, 2:00 PM.
- Lab 2. Arrays and iteration. Automatic tests. Due: Saturday, February 10, 2:00 PM.
- Lab 3. Pointers. Due: Saturday, February 17, 2:00 PM.
- Lab 4. Structs. Due: Saturday, February 23, 2:00 PM.
- Lab 5. Memory problems. Due: Saturday, March 10, 2:00 PM.
- Lab 6. Binary files. Due: Saturday, March 31, 2:00 PM.
4. Assignments
Programming assignments.
To submit: join the Google classroom (code 3wclclu)