1 getpid function,getppid function , get process ID, get parent process ID
#include <unistd.h>pid_t getpid (void) pid_t getppid (void) uid_t Getuid (void) gets the actual user iduid_t Geteuid (void) to obtain a valid user idgid_t Getgid (void ) Get the actual group idgid_t getegid (void) to get a valid group ID
2 Fork function, the current process creates a new process
#include <unistd.h>pid_t fork (void)
The child process returns 0, the parent process returns the child process ID, and an error returns -1
3 When the parent process terminates before the child process, the parent process of the child process is converted to the init process, guaranteeing that each process has a parent process .
When a child process terminates before the parent process, the kernel retains some information for each terminating process, and the parent process can call wait, andthewaitpid function obtains this information.
If a process has been terminated, but the parent process does not dispose of it (getting information about it, freeing the owning resource), such a process is called a zombie process
When a child process becomes a child process of the INIT process, when it terminates,theinit process immediately calls waitto prevent it from becoming a zombie process
4 When a child process terminates (normal or abnormal), the kernel sends a SIGCHLD signal to the parent process , and the default option is to ignore the signal
5 Wait function
#include <sys/wait.h>pid_t wait (int *intint options)
6 exec function, starting from the main function to re-execute the new program
#include <unistd.h>execl take pathname and parameter EXECLP search for executable file in path, execle use new environment list EXECV parameter list
7 system functions, very easy to perform some operations
#include <stdlib.h>int system (char* cmdstring);
the system principle is to call fork, exec a shell in the subprocess, and Cmdstring , the main process calls the waitpid child process for aftercare
UNIX Environment Advanced Programming Learning Note (V): Process Control