/*
============================================================================
Name : test.c
Author : blank
Version :
Copyright : Your copyright notice
Description : 程序清单 8-8 exec函数实例,a.out是程序8-9产生的可执行程序============================================================================
*/ #include "ourhdr.h"
#include <sys/wait.h> char *evn_init[] = { "USER=unknown", "PATH=/tmp", NULL};
int main(int argc, char *argv[])
{
pid_t pid; if ((pid = fork()) < ){
err_sys("fork error");
}else if (pid == ){
// specify pathname, specify environment
if (execle("/home/blank/workspace/test/src/a.out", "a.out", "myarg1",
"MY ARG2", (char *), evn_init) < ){
err_sys("execel error");
}
} if (waitpid(pid, NULL, ) < ){
err_sys("waitpid error");
} if ((pid = fork()) < ){
err_sys("fork error");
}else if (pid == ){
// specify filename, inherit environment
if (execlp("./a.out", "a.out", "only 1 arg", (char *)) < ){
err_sys("execlp error");
}
} exit();
}