添加 src/execlp.c
This commit is contained in:
parent
688e29cf57
commit
62f1e98f54
31
src/execlp.c
Normal file
31
src/execlp.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char * argv[])
|
||||||
|
{
|
||||||
|
int pid;
|
||||||
|
/* fork another process */
|
||||||
|
pid = fork();
|
||||||
|
if (pid<0)
|
||||||
|
{
|
||||||
|
/* error occurred */
|
||||||
|
fprintf(stderr,"Fork Failed!");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
else if (pid==0)
|
||||||
|
{
|
||||||
|
/* child process */
|
||||||
|
execlp("/bin/ls","ls",NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* parent process */
|
||||||
|
/* parent will wait for the child to complete*/
|
||||||
|
wait(NULL);
|
||||||
|
printf("Child Complete!");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user