POSIX Processes API

Creating processes

fork

// Returns new Process ID in parent
// Returns 0 in child
int fork(void);
Why fork?

  • Most calls to fork are followed by execve
    • could combine into one spawn system call
    • load and execute new child process
  • Occasionally useful to fork one process
    • For webservers, parallelism
    • Create one process per core
  • Simplicity
    • no arguments needed

waitpid

int waitpid(int pid, int *status, int options);

Deleting Processes

exit

void exit(int status);

Kill

int kill(int pid, int sig);
A signal is a software interrupt

  • SIGTERM is most common
    • kills process by default
    • applications can catch to do clean up
  • SIGKILL is stronger
    • kill process always

Running Programs

execve

int execve (char *prog, char **argv, char **envp)
Execve is usually called through wrapper functions

int execvp(char *prog, char **argv);
  • searches PATH for prog
  • then runs execve
int execlp(char *prog, char *arg, …);
  • lp stands for list parameters
  • list arguments one at a time
    • end with NULL