fork 子進(jìn)程

waitpid() IBM 系列文章精粹,W開頭的系列宏定義函數(shù)

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 僵尸進(jìn)程 <defunct>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 子進(jìn)程模塊:childProcess = require("child_process"); 1、var spaw...
    剁剁爺閱讀 1,449評(píng)論 0 0
  • 在node.js中,只有一個(gè)線程執(zhí)行所有操作,如果某個(gè)操作需要大量消耗 CPU 資源的情況上,后續(xù)操作需要等待。 ...
    _1633_閱讀 764評(píng)論 0 0
  • 最近在做12306爬蟲,剛好遇到了Node子進(jìn)程的應(yīng)用場景,不總結(jié)不快: Node的child_process模塊...
    Devildi已被占用閱讀 788評(píng)論 0 1
  • 作者:Vamei 出處:http://www.cnblogs.com/vamei 歡迎轉(zhuǎn)載,也請(qǐng)保留這段聲明。謝謝...
    Joncc閱讀 378評(píng)論 0 1
  • 進(jìn)程 - 定義 進(jìn)程是程序的執(zhí)行示例 程序在 CPU 上執(zhí)行的活動(dòng)叫做進(jìn)程 實(shí)際上并沒有明確的定義,只有一些規(guī)則 ...
    littleyu閱讀 2,323評(píng)論 0 0

友情鏈接更多精彩內(nèi)容