[haiku-bugs] [Haiku] #13546: wait4() doesn't seem to work

  • From: "korli" <trac@xxxxxxxxxxxx>
  • Date: Tue, 06 Jun 2017 18:13:25 -0000

#13546: wait4() doesn't seem to work
-------------------------------+------------------------------
 Reporter:  korli              |        Owner:  nobody
     Type:  bug                |       Status:  new
 Priority:  normal             |    Milestone:  Unscheduled
Component:  System/libroot.so  |      Version:  R1/Development
 Keywords:                     |   Blocked By:
 Blocking:                     |  Has a Patch:  0
 Platform:  All                |
-------------------------------+------------------------------
 Test program:
 {{{
 /*
  * Copyright 2007, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. All rights
 reserved.
  * Distributed under the terms of the MIT License.
  */


 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/resource.h>
 #define _BSD_SOURCE
 #include <sys/wait.h>
 #include <unistd.h>


 /*!
         wait() should wait only once. If any argument is given, waitpid()
 should return
         an error (and errno to ECHILD), since there is no child with that
 process group ID.
 */


 int
 child2()
 {
         sleep(2);
         return 2;
 }


 //! exits before child 2
 int
 child1()
 {
         setpgrp();
                 // put us into a new process group

         pid_t child = fork();
         if (child == 0)
                 return child2();

         sleep(1);
         return 1;
 }


 int
 main(int argc, char** argv)
 {
         bool waitForGroup = argc > 1;

         pid_t child = fork();
         if (child == 0)
                 return child1();

         struct rusage usage;
         pid_t pid;
         do {
                 int childStatus = -1;
                 pid = wait4(-1, &childStatus, 0, &usage);
                 printf("wait4() returned %ld (%s), child status %d\n",
                         pid, strerror(errno), childStatus);
         } while (pid >= 0);

         return 0;
 }

 }}}

 Haiku strace output
 {{{
 [   581] _kern_image_relocated(0xf6d) (409 us)
 [   581] _kern_set_area_protection(0x2cce, 0x5) = 0x00000000 No error (11
 us)
 [   581] _kern_set_area_protection(0x2cd0, 0x5) = 0x00000000 No error (10
 us)
 [   581] _kern_set_area_protection(0x2cd2, 0x5) = 0x00000000 No error (23
 us)
 [   581] _kern_get_system_info(0x72d84998) = 0x00000000 No error (7 us)
 [   581] _kern_get_system_info(0x72d84798) = 0x00000000 No error (4 us)
 [   581] _kern_reserve_address_range([0x18033000], 0x7, 0x48000000) =
 0x00000000 No error (7 us)
 [   581] _kern_create_area("heap", 0xc6b980, 0x1, 0x40000, 0x0, 0x33) =
 0x00002cd6 (15 us)
 [   581] _kern_fork() = 0x00000247 (241 us)
 [   581] _kern_wait_for_child(0xffffffff, 0x0, 0x72d84b64) = 0x00000247
 (999999 us)
 [   581] --- Child exited (Child exited) ---
 [   581] _kern_get_team_usage_info(0x247, 0x0, 0x72d84bb8, 0x10) =
 0x80001103 Operation on invalid team (2 us)
 [   581] _kern_read_stat(0x1, (nil), false, 0x72d83390, 0x58) = 0x00000000
 No error (4 us)
 [   581] _kern_ioctl(0x1, TCGETA, 0x72d83338, 0x20) = 0x00000000 No error
 (5 us)
 wait4() returned -1 (No error), child status 1
 [   581] _kern_write(0x1, 0xffffffffffffffff, 0x180571b0, 0x2f) =
 0x0000002f (1379 us)
 [   581] _kern_exit_team(0x0) (9 us)
 }}}

 Linux output
 {{{
 wait4() returned 22104 (Success), child status 256
 wait4() returned 4294967295 (No child processes), child status -1
 }}}

--
Ticket URL: <https://dev.haiku-os.org/ticket/13546>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: