创建的新的子进程在调用execv执行新的程序段(开始独立于父进程执行)的时候,子进程用户空间栈的安排应该是怎样的呢?参数是如何传递的呢?
编写如下两个程序:
程序一:test1.c
#include <stdio.h>
int main(int args, char* argv[]) {
char s[5] = "ABCD";
while(1) {
printf("%s\n", s);
printf("%s\n", argv[1]);
}
return;
}
gcc -g -o test1 test1.c
程序二:test.c
#include "../include/apue.h"
void main() {
pid_t pid;
char *args[] = {"/bin/echo", "Hello", "World!", NULL};
if((pid = fork()) < 0)
err_sys("fail to fork!");
else if(pid == 0) {
execve("./test1", args, NULL);
}
}
gcc -g -o test test.c
我们来调试一下parent,涉及到多进程程序的调试,可以参考文章http://w