Process creation issue


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;
}
Try:

#include <sys/wait.h>

somewhere.
Use waitpid() instead , also include sys/wait.h as hinted by firedraco .
Thanks a bunch!
Topic archived. No new replies allowed.