class: title # Processes and System Calls ## CSC 213 – September 8, 2025 --- # Agenda for Today 1. Department Events 2. Upcoming Work 3. Processes & System Calls 4. ~~More C Practice (if there's time)~~ 5. Wrap Up --- # Department Events ## CS Table: Developer Experience with AI Coding Assistants .indent[ Tuesday, September 9th at noon in JRC 224C ] ## CS Extra: Off Campus Study in Computer Science .indent[ Thursday, September 11th at 4:15pm in Noyce 3821 ] *To receive 0.25% extra credit, send an email to let me know you attended no more than 48 hours after the event.* --- class: section, blue # Upcoming Work --- # Assignment 1: Ngram Generator **Due:** Monday, September 8th by 11:59pm ## Questions **Getting the starter code produces a `git` error. What should I do?** The `git` error will print a command you should run first, then you can retry. Or run this command first and `git` should stop complaining: ``` git config --global --add safe.directory "*" ``` --- # Assignment 2: Sorted List **Due:** Monday, September 15th by 11:59pm Let's take a quick look at the assignment. ## Questions *None yet.* --- 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's 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 tonight. Don't forget to review the C style guidelines from last week's class slides. The sorted list assignment is due next Monday. We'll follow this schedule for most of the semester. ## Reading Review lab instructions before class