C Programming Tutorials
Quick guides for C & UNIX
Introduction
This is a growing list of very brief tutorials on various aspects of C and Unix programming. By Unix, I refer to the various flavors of Linux, Solaris (SunOS), System V, FreeBSD, NetBSD, OpenBSD, Meego, and OS X. I test the examples on a Mac running OS X. While I will try to point out any modifications needed for Linux and/or SunOS, you may have to tweak some of the #include headers. If things aren't compiling, be sure to check the manual pages on your system for proper usage (e.g., man fork). The usage syntax will tell you what headers need to be included.
My goal is to make the tutorials and sample code as short as possible — something you can use and build on if you want to. Many of the funcitons or system calls presented have extra layers of complexity and options that I will not cover. Be sure to consult the man page or more detailed sources if you want to understand the details.
Playing with processes
- Use getpid to get your process' ID
- Use getppid to get a parent process' ID
- Use fork to create processes
- Use exec to run another program
- Use fork and exec to create a new process and run a program
- Use wait to wait for a child to exit
- Use signal to be alerted that a child process terminated
I/O redirection and IPC
- How to redirect output with dup2
- How to pipe output from one process to another
- Determine if a file is a terminal device with isatty