啊?
所以使用 fork() + exec() 不是呼?
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
pid_t child_pid;
int status;
char prog[]="/bin/ls";
printf("** Execuing program: ls -l /bin/gzip **\n\n");
child_pid = fork();
if (child_pid < 0) {
exit(1);
}
if (child_pid != 0) // parent
waitpid(child_pid,&status,0);
else
execl(prog,prog,"-l","/bin/gzip",NULL);
printf("\nchild return exit code: %d\n",WEXITSTATUS(status));
return 0;
}
** Execuing program: ls -l /bin/gzip **
-rwxr-xr-x 1 root root 63080 2008-12-20 02:23 /bin/gzip
child return exit code: 0