| 1 | /* |
| 2 | test that waitpid works expected way |
| 3 | */ |
| 4 | #include <sys/wait.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <stdio.h> |
| 7 | #include <unistd.h> |
| 8 | |
| 9 | int main() { |
| 10 | pid_t pid; |
| 11 | int status; |
| 12 | |
| 13 | switch (pid = fork()) { |
| 14 | case 0: |
| 15 | execl("/bin/cp", "/bin/cp", "-a", "/tmp/test", "/tmp/test2", NULL); |
| 16 | exit(0); |
| 17 | |
| 18 | case -1: |
| 19 | perror("fork()"); |
| 20 | exit(1); |
| 21 | |
| 22 | default: |
| 23 | sleep(1); |
| 24 | if (-1 == waitpid(pid, &status, 0)) { |
| 25 | perror("waitpid:cp"); |
| 26 | exit(2); |
| 27 | } |
| 28 | printf("waitpid: %x\n", status); |
| 29 | exit(0); |
| 30 | } |
| 31 | } |