Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

wait4(2) do not fail with WNOHANG if there is no child



Hi,

Just encountered a case where wait(4) + WNOHANG do not fail with
expected ECHILD when there is no process to wait.

The attached testcase illustrate this :

  pid = wait4(-1, NULL, 0, NULL);
  assert(pid == -1 && errno == ECHILD);
  pid = wait4(-1, NULL, WNOHANG, NULL);
  assert(pid == -1 && errno == ECHILD);

The first wait(4) call fails as expected, but the second one makes the
assert fire because pid == 0 ... where i would have expected same
failure as previous (-1 + ECHILD)

njoly@raya [netbsd/funcs]> make wait4
cc -g -Wall -Werror   -o wait4 wait4.c
njoly@raya [netbsd/funcs]> ./wait4
assertion "pid == -1 && errno == ECHILD" failed: file "wait4.c", line
13, function "main"

Thanks.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
#include <sys/wait.h>

#include <assert.h>
#include <errno.h>

int main() {
  pid_t pid;

  pid = wait4(-1, NULL, 0, NULL);
  assert(pid == -1 && errno == ECHILD);
  pid = wait4(-1, NULL, WNOHANG, NULL);
  assert(pid == -1 && errno == ECHILD);

  return 0; }


Home | Main Index | Thread Index | Old Index