32 lines
667 B
C
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;
|
|
}
|