标签:
我们先看下面的程序:
#include <stdio.h>
int main()
{
	int child;
	char *args[] = {"/bin/echo", "Hello", "World!", NULL};
	
	if(!(child = fork()))
	{
		/* child */
		execve("/bin/echo", args, NULL});
		printf("I am back, something is wrong!\n");
	}	
	else
	{
		/* father */
		wait4(child, NULL, 0, NULL);
	}
}参考Linux内核源代码情景分析-fork()。fork的返回值参考Linux内核源代码情景分析-系统调用,返回的是子进程的pid,非0,所以执行else部分的程序。
二、父进程执行wait4,并调用schedule切换到子进程
标签:
原文地址:http://blog.csdn.net/jltxgcy/article/details/44451279