class: title # Processes and System Calls ## CSC 213 – September 4, 2026 --- # Agenda for Today 1. Upcoming Work 2. Processes & System Calls 4. More C Practice _(if there's time)_ 5. Wrap Up --- class: section, blue # Upcoming Work --- # Assignment 1: Ngram Generator **Due:** Tuesday, September 8th by 11:59pm ## Questions **Is remote access to MathLAN working?** It seems like it is back now. This assignment should also work on your own computer if you have a C programming environment set up (regular macOS or Windows with WSL). **What's the difference between `argv` input and `getchar` input?** The `argv` array holds command line arguments passed to the program at startup. When you call `getchar` or similar functions, that's asking the user to type something at that moment after the program has already started. --- # Assignment 2: *Coming Soon* **Due:** Monday, September 14th by 11:59pm I will normally release assignments on Mondays, but I'll send this one out later today via email so you can get started if you have time over the long weekend. --- class: section, blue # Processes & System Calls --- # Discussion: Process Basics **Questions for think, pair, share:** 1. What is a process, and why is it a useful abstraction for the OS to provide? 2. What is a system call, and why do we need this abstraction? 3. What is limited direct execution? *Start by thinking of answers on your own. I will let you know when to start discussion.* --- # Process API: Example 1 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("Hello,\n"); fork(); printf("world.\n"); } ``` --- # Process API: Example 2 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { int counter = 0; fork(); counter++; printf("counter is %d\n", counter); } ``` --- # Process API: Example 3 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { pid_t child_id = fork(); if (child_id == 0) { printf("A\n"); } else if (child_id > 0) { printf("B\n"); } else { perror("fork failed"); exit(EXIT_FAILURE); } } ``` --- # Process API: Example 4 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { pid_t child_id = fork(); if (child_id == 0) { printf("A\n"); } else if (child_id > 0) { wait(NULL); printf("B\n"); } else { perror("fork failed"); exit(EXIT_FAILURE); } } ``` --- # Process API: Example 5 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("ls", "ls", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 6 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("ls", "noyce", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 7 What output do you expect this program to produce? Assume all necessary includes are above the provided code. ```c int main() { printf("A\n"); execlp("noyce", "ls", "-l", NULL); printf("B\n"); } ``` --- # Process API: Example 8 What output do you expect this program to produce? ```c int main() { pid_t child_id = fork(); if (child_id == 0) { execlp("ls", "ls", "-l", NULL); perror("exec failed"); exit(EXIT_FAILURE); } else if (child_id > 0) { int status; wait(&status); printf("Child exited with status %d\n", WEXITSTATUS(status)); } else { perror("fork failed"); exit(EXIT_FAILURE); } } ``` --- class: section, blue # More C Practice *(if there's time)* --- # More C Practice: Stack Implementation We are going to implement a stack that stores integers. Before we start, we should answer two questions: 1. What is the *interface* for a stack of integers? That is, what functions will we use to interact with stacks? 2. How will we store the stacks' contents? *Start by thinking of answers on your own. I will let you know when to start discussion.* --- class: section, gray # Stack Implementation --- class: section, blue # Wrap Up --- # Reminders ## Assignment The Ngram Generator assignment is due on Tuesday night. I have bookable office hours early next week if you need help. Don't forget you can also refer to the in-class demos; the `charsort` example program might include some helpful pieces you could incorporate in your assignment (remember to cite). Do your best to follow the C code style guidelines from our previous slides. ## Reading Review the instructions for our first lab before Wednesday's class. I'll publish these soon.