1/* 2 * Copyright 2007, Jérôme Duval. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include <errno.h> 8#include <stdio.h> 9#include <string.h> 10#include <sys/wait.h> 11#include <unistd.h> 12 13 14/*! 15 wait()/waitpid() should return -1 and set errno to ECHILD, since there 16 are no children to wait for. 17*/ 18int 19main() 20{ 21 int childStatus; 22 pid_t pid = wait(&childStatus); 23 printf("wait() returned %ld (%s)\n", pid, strerror(errno)); 24 25 pid = waitpid(-1, &childStatus, 0); 26 printf("waitpid(-1, ...) returned %ld (%s)\n", pid, strerror(errno)); 27 28 pid = waitpid(0, &childStatus, 0); 29 printf("waitpid(0, ...) returned %ld (%s)\n", pid, strerror(errno)); 30 31 pid = waitpid(getpgrp(), &childStatus, 0); 32 printf("waitpid(%ld, ...) returned %ld (%s)\n", getpgrp(), pid, strerror(errno)); 33 34 return 0; 35} 36 37