waitpid() IBM 系列文章精粹,W开头的系列宏定义函数
- Notes on Wait & Waitpid;
- WIFEXITED–Query status to see if a child process ended normally;
- wait–Wait for status information from a Child process;
- waitpid–Obtain status information from a child process;
- WEXITSTATUS–Obtain exit status of a child process;
- Exit status of a child process in Linux;
- Process Completion Status;
fork()
Some of the important points on fork() are as follows:
The parent will get the child process ID with non-zero value.
Zero Value is returned to the child.
If there will be any system or hardware errors while creating the child, -1 is returned to the fork().
With the unique process ID obtained by the child process, it does not match the ID of any existing process group.
pipe()
int pipe(int fds[2]);
Parameters :
fd[0] will be the fd(file descriptor) for the read end of pipe.
fd[1] will be the fd for the write end of pipe.
Returns : 0 on Success, -1 on error.
execvp()
What happens to our C program now?
This function will give the control of the current process (C program) to the command. So, the C program is instantly replaced with the actual command.
So, anything that comes after execvp() will NOT execute, since our program is taken over completely!
However, if the command fails for some reason, execvp() will return -1.
So, whenever you use execvp(), if you want to maintain your C program, you generally use fork() to first spawn a new process, and then use execvp() on that new process.
This is called the “fork-exec” model, and is the standard practice for running multiple processes using C.
zombie 僵尸进程 <defunct>
- Zombies can be identified in the output from the Unix ps command by the presence of a "
Z
" in the "STAT" column.
- kill 掉僵尸进程的父进程即可杀死僵尸进程。
- How to kill zombie process @stackoverflow;
- What Is a “Zombie Process” on Linux?:说的清楚。