study/linux/linux_c/progess/exec.c
2020-02-23 22:23:40 +08:00

32 lines
667 B
C

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/*
* === FUNCTION ======================================================================
* Name: main
* Description:
* fork()和 execl() 联合使用
* =====================================================================================
*/
int main ()
{
int pid,status;
pid = fork();
switch(pid){
case -1:
perror("fork failed");
exit(1);
case 0:
execl("/bin/ls","ls","-l","--color",NULL);
perror("execl failed");
exit(1);
default:
wait(&status);
printf("ls completed\n");
printf("status = %d\n",status);
exit(0);
}
return EXIT_SUCCESS;
}