fork 子进程

waitpid() IBM 系列文章精粹,W开头的系列宏定义函数

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.
call fork after creating a pipe, then the parent and child can communicate via the pipe.

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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 子进程模块:childProcess = require("child_process"); 1、var spaw...
    剁剁爷阅读 5,174评论 0 0
  • 在node.js中,只有一个线程执行所有操作,如果某个操作需要大量消耗 CPU 资源的情况上,后续操作需要等待。 ...
    _1633_阅读 3,921评论 0 0
  • 最近在做12306爬虫,刚好遇到了Node子进程的应用场景,不总结不快: Node的child_process模块...
    Devildi已被占用阅读 3,973评论 0 1
  • 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢...
    Joncc阅读 2,498评论 0 1
  • 进程 - 定义 进程是程序的执行示例 程序在 CPU 上执行的活动叫做进程 实际上并没有明确的定义,只有一些规则 ...
    littleyu阅读 6,266评论 0 0