This preview shows page 1. Sign up to view the full content.
Unformatted text preview: r-handling and the error-handling wrappers used throughout the book. The wrappers are deﬁned in a ﬁle called csapp.c and their prototypes are deﬁned in a header ﬁle called csapp.h. For your reference, Appendix A provides the sources for these ﬁles. 8.4 Process Control
Unix provides a number of system calls for manipulating processes from C programs. This section describes the important functions and gives examples of how they are used. 404 CHAPTER 8. EXCEPTIONAL CONTROL FLOW 8.4.1 Obtaining Process ID’s
Each process has a unique positive (non-zero) process ID (PID). The getpid function returns the PID of the calling process. The getppid function returns the PID of its parent (i.e., the process that created the calling process).
#include <unistd.h> #include <sys/types.h> pid t getpid(void); pid t getppid(void);
returns: PID of either the caller or the parent The getpid and getppid routines return an integer value of type pid t, which on Linux systems is deﬁned in types.h as an int. 8.4.2 Creating and Terminating Processes
From a programmer’s perspective, we can think of a process as being in one of three states: ¯ ¯ ¯ Running. The process is either executing on the CPU, or is waiting to be execute...
View Full Document
- Spring '10
- The American