***********我又来求指点了*********

生活简单到无聊 生活简单到无聊 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<errno.h>
#include<sys/types.h>

int main(int argc, char* argv[])
{

int i = 0;

pid_t pid = -1;

fprintf(stdout, "parent pid[%d], i[%d]\n", getpid(), i);

if((pid = vfork()) < 0)
{
fprintf(stderr, "fork failed!! errorno = %d\n", errno);
return 0;
}
else if(pid > 0)
{
fprintf(stdout, "after fork, parent pid[%d], i[%d]\n", getpid(), i);
}
else
{
system("find . -type f");
}


fprintf(stdout, "process end. pid[%d], i[%d]\n", getpid(), i);

return 0;
}



运行结果:
parent pid[20000], i[0]
./core.17552
./libshow.a
./dup2.c
./csdn.c
./main
./base/baseMath.o
./base/baseMath.c
./base/libbaseMath.a
./base/libbaseMath.so
./base/baseMath.h
./test.cpp
./stat.c
./power.c
./tag.c
./libshow.so
./unlink
./unlink.c
./book.c
./show.o
./a.bat
./show.c
./reservword.c
./fileop.c
./code.c
process end. pid[20001], i[0]
after fork, parent pid[20000], i[0]
process end. pid[20000], i[0]
Segmentation fault (core dumped)



为什么最后core了。。。。?!
...全文
评论 4
收藏 已收藏
分享
返回顶部