Process creation: An exec'd process should be run in the space of a process that is the child of bash (the shell). This means that fork() and exec() are related in that ordinarily an exec() follows a fork() fork() commands the system to create a new process Notes: fork() is called once and returns twice once in the parent that called it  (return value is child's pid) once in the child process that was created (return value is 0) exec is called and doesn't return exec Family of System Calls Six versions, incorporating path search designation of environment Separate environment from your shell, e.g. different $PATH passing arguments to called program list A process always receives its command-line arguments as a vector vector        int execl(const char *path, const char *arg, ...); Provide the command-line args as a comma-separated list. Must be NULL terminated        int execlp(const char *file, const char *arg, ...);  Also, path search for program        int execle(const char *path, const char *arg,      ..., char * const envp[]); Provide the environment in which it executes        int execv(const char *path, char *const argv[]); vector only        int execvp(const char *file, char *const argv[]); vector with path search int execvpe(const char *file, char *const argv[],  char *const envp[]); vector, path search, environment Called program occupies environment of caller (takes its pid, as new process isn't created). Only replaces text, data, heap, and stack segments of caller of exec. Every process in a Unix/Linux system is a descendant of the init process, PID 1. Shell Execution - Part 1 To execute a command in the shell: Fork a child in which to run the command Child execs that command Parent issues wait() wait() suspends (in the parent) until informed by the child that the exec is complete Child terminates after informing parent Parent resumes after being informed. Note: If a process is run in the background (by appending &), the parent does not suspend.    However, the child must be brought to the foreground (using fg) in order to use stdin. fork(): Child gets copy of parent's environment (including data space) as it is at time of fork. See PPT Set 2, Slide 18 File Pointer Modes: r, w, a ... Respectively, read, write, append.    A + on r+ means writing, too. With w and a, a + means read also. From the documentation: vfork note: Earlier, the parent suspended while the child ran in its space. That is no longer true. wait(): The wait() command is used by a parent to suspend until its child completes and signals its parent (SIGCHLD). AQt that time the parent can 'collect' its child and the provided data - Note that a parent can have multiple children. A wait() needs to be issued for each one. Otherwise, zombie process(es) occur.