1. Replace process mirroring
#include <unistd.h>
extern char **environ;
int execl (const char *path, const Char*arg, ..., (char*) 0);
int EXECLP (const char *file, const Char*arg, ..., (char*) 0);
int execle (const char *path, const Char*arg, ..., char * const envp[]);
int execv (const char *path, char *constargv[]);
int EXECVP (const char *file, char *constargv[]);
int Execve (const char *file, char *const argv[], char *const envp[]);
1) execl, EXECLP, execle parameters are variable, end with null pointer; Execv, EXECVP The second argument is an array of strings.
2 function passes the ARGV parameter to the main function.
3 The function ending with P searches the PATH environment variable to find the new program, and does not exist by using an absolute path to pass to the function.
4 The EXEC function does not return the function that called it.
2. Copying Process objects
#include <unistd.h>
#include <sys/types.h>
pid_t fork (void);
The new process is exactly the same as the original process, executing the code exactly the same, just with its own data space, environment, and file descriptor.
return value:
-1: Creation failed;
0: Current process for subprocess;
Non 0: The current process is the parent process.
3. Process Waiting
#include <sys/types.h>
#include <sys/wait.h>
pid_t Wait (int*stat_loc);
pid_t waitpid (pid_t pid, int* stat_loc, int options);
int Waitid (idtype_tidtype, id_t ID, siginfo_t *infop, int options);
Pauses the parent process until the child process is finished.
Stat_loc: