| Sakayapo (2) | |
|
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; } | |
|
|
|
| firedraco (5495) | |
Try:#include <sys/wait.h> somewhere. | |
|
|
|
| ahmedkhan (4) | |
| Use waitpid() instead , also include sys/wait.h as hinted by firedraco . | |
|
|
|
| Sakayapo (2) | |
| Thanks a bunch! | |
|
|
|