IT628 Systems Programming Course Outline
Document Details
Uploaded by Deleted User
Tags
Summary
This document is a course outline for IT628: Systems Programming. It covers topics such as concurrent programming, which includes processes, signals, pipes, threads, and synchronization, and network programming, including sockets and servers. The course also covers system calls and their categories, including file system operations and inter-process communication. Reference books and a grading breakdown for the course are also included.
Full Transcript
IT628: Systems Programming Course outline, process creation 1 What’s this course all about? Operating systems provide a set of constructs and well-defined primitives to simplify application development You will learn how to write applications that exploit...
IT628: Systems Programming Course outline, process creation 1 What’s this course all about? Operating systems provide a set of constructs and well-defined primitives to simplify application development You will learn how to write applications that exploit important OS features Often we will present an OS concept first and then the system calls associated with that concept 2 Main topics we’ll cover Concurrent programming processes, signals, pipes, threads, synchronization Network programming sockets and servers 3 System calls A request for the OS to do something on behalf of the user’s program Example fork() exec() Don’t confuse system calls with libc calls strcpy() 4 Main categories of system calls File system Low-level file I/O E.g., creat, open, read, write, lseek, close Multi-tasking mechanisms Process control E.g., fork, wait, exec, exit, signal, kill Inter-process communication E.g., pipe, dup, dup2 5 Classroom organization Standard lecture format with exercises sprinkled in for class discussion We’ll also demo code examples in class Questions are ALWAYS encouraged (both directions) 6 Classroom Etiquette Come on time to both class and labs Talking, cell phones, etc. will not be tolerated 7 Reference books Keith Haviland, Dina Gray and Ben Salama “UNIX System Programming”, Addison-Wesley Randal Bryant and David O’Hallaron “Computer Systems: A Programmer’s Perspective”, Pearson India Brian Kernighan and Dennis Ritchie “The C Programming Language, Second Edition”, Prentice Hall India 8 Grade breakdown Exams (70%): two insem exams and final two insems weighted 20% final weighted 50% (covers entire course) Lab exercises (checkoffs) and homework (30%) weighted 20%, 10% lab attendance is mandatory 9 Processes A process is the basic unit of execution in an OS A process is a running instance of a program Program = static file (image) Process = executing program = program + execution state Two processes are said to run concurrently when instructions of one process are interleaved with the instructions of the other process 10 Context switching Transferring control from the current process to another process is called a context switch OS saves the state of the current process, restores the state of the other process, and passes control to the new process From a human observer’s point of view, many processes appear to proceed simultaneously 11 fork() fork creates a new process the process created (child) runs the same program as the creating (parent) process and starts with the same PC, the same CPU registers, the same open files, etc. 12 Ppare intntmain(){ fork(); foo(); } OS 13 Ppare intntmain(){ fork(); foo(); } OS 14 Ppare Pchild intntmain(){ int main(){ fork(); fork(); foo(); foo(); } } OS creates 15 Ppare Pchild intntmain(){ int main(){ fork(); fork(); foo(); foo(); } } OS 16 fork(), when called, returns twice (to each process @ the next instruction) int main() { fork(); printf(“Hello world!\n”); } Hello world! Hello world! 17 int main() { fork(); fork(); printf(“Hello world!\n”); } Hello world! Hello world! Hello world! Hello world! 18 int main() { fork(); fork(); fork(); printf(“Hello world!\n”); } Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! Hello world! 19 return value of fork() typedef int pid_t; pid_t fork(); system-wide unique process identifier child’s pid (> 0) is returned in the parent sentinel value (0) is returned in the child 20 void fork0() { if (fork()==0) printf(“Hello from Child!\n”); else printf(“Hello from Parent!\n”); } main(){ fork0(); } Hello from Child! Hello from Parent! (or) Hello from Parent! Hello from Child! 21 void fork3() { int i; sum = 0; fork(); for (i=1 ; i