当前位置: 技术问答>linux和unix
fork时的copy-on-write问题
来源: 互联网 发布时间:2016-11-04
本文导语: unix环境高级编程8.3节讲fork时的copy-on-write技术时,有段代码如下(稍微做了点修改): #include #include int glob=6; char buf[]="a write to stdoutn"; int main(void) { int var; pid_t pid; var=88; if(write(STDOUT_FILENO,buf,sizeof(buf)-1)...
unix环境高级编程8.3节讲fork时的copy-on-write技术时,有段代码如下(稍微做了点修改):
#include
#include
int glob=6;
char buf[]="a write to stdoutn";
int main(void)
{
int var;
pid_t pid;
var=88;
if(write(STDOUT_FILENO,buf,sizeof(buf)-1) != sizeof(buf)-1)
{
printf("write errorn");
exit(1);
}
printf("before forkn");
if(pid=fork()