previous
 next 
CS 3733 Operating Systems Notes: USP Chapter 3 Highlights


Read USP Sections 3.1-3.5 carefully.


fork:
   pid_t fork(void);
pid_t is an integer data type: may be short, int, long, or simething else.


wait:
   pid_t wait(int *stat_loc);
   pid_t waitpid(pid_t pid, int *stat_loc, int options);

waitpid:
Allows you to wait for a particular process, or all processes if pid is -1. Important option is NOHANG which will return 0 if there is a specified child to wait for but it has not yet terminated.

Important values of errno:
ECHILD no unwaited for children
EINTR a signal was caught

Three main reason for wait to return information about a child:
Correct way to check status:
   #include <sys/wait.h>

   WIFEXITED(int stat_val)
   WEXITSTATUS(int stat_val)
   WIFSIGNALED(int stat_val)
   WTERMSIG(int stat_val)
   WIFSTOPPED(int stat_val)
   WSTOPSIG(int stat_val)
They are used in pairs.
If WIFEXITED returns true, the child executed normally and the return status (at most 8 bits) can be gotten with WEXITSTATUS.

Note that WEXITSTATUS returns an 8-bit unsigned integer.


exec
   #include <unistd.h>

   extern char **environ;
   int execl(const char *path, const char *arg0, ... /*, char *(0) */);
   int execle (const char *path, const char *arg0, ... /*, char *(0),
               char *const envp[] */);
   int execlp (const char *file, const char *arg0, ... /*, char *(0) */);
   int execv(const char *path, char *const argv[]);
   int execve (const char *path, char *const argv[], char *const envp[]);
   int execvp (const char *file, char *const argv[]);

You must understand all 6 forms.

Next Notes

Back to Chapter 3