Oct 27, 2012 at 2:31am UTC
Hi,
The program listed below is illustrating the process creation.
However the wait(NULL) method appears to be out of scope frequently.
That is known by a compiling error when building it.
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
/*fork a child process*/
pid = fork();
if(pid < 0){/*error occured */
fprintf(stderr, "Fork Failed");
return 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");
}
return 0;
}
Oct 27, 2012 at 6:50am UTC
Try:
#include <sys/wait.h>
somewhere.
Oct 27, 2012 at 5:50pm UTC
Use waitpid() instead , also include sys/wait.h as hinted by firedraco .