On Tue, May 29, 2012 at 10:08 PM, Marc Lehmann <schm...@schmorp.de> wrote:
> You also don't call waitpid on your children - can you add error checking
> to all functions you call, to make sure you really do wait for your
> children (especially check fork returns)? Most likely you run out of
> process slots and fork fails, which your code "misinterprets" as a hang.

No, it's not that. Attached is the program that checks the error codes
and also waits for a child using child watcher. Still fails.
/* gcc -DEV_STANDALONE=1 testsigchld.c -o testsigchld 
 *
 * Expected output: infinite sequence of "*."
 *
 * Actual output:
 *   denis@denis-laptop:~/work/libev-cvs$ ./testsigchld 
 *   *.*.*.Alarm clock
 *
 *   (number of iterations is different each time)
 *
 * */
#include "ev.c"


void stop_child(struct ev_loop* loop, ev_child *w, int revents) {
    ev_child_stop(loop, w);
}

int CHECK(int retcode) {
    if (retcode < 0) {
        perror("fail");
        _exit(1);
    }
    return retcode;
}

void subprocess(void) {
    int pid;
    if (pid = CHECK(fork())) {
        struct ev_child child;
        ev_child_init(&child, stop_child, pid, 0);
        ev_child_start(EV_DEFAULT, &child);
        ev_run(EV_DEFAULT, 0);
        CHECK(fprintf(stderr, "*"));
    }
    else {
        _exit(0);
    }
}


void test_main(void) {
    int pid = CHECK(fork());
    if (!pid) {
        ev_loop_fork(EV_DEFAULT);
        subprocess();
        _exit(0);
    }

    alarm(5);
    
    struct ev_child child;
    ev_child_init(&child, stop_child, pid, 0);
    ev_child_start(EV_DEFAULT, &child);
    ev_run(EV_DEFAULT, 0);
    
    alarm(0);
}

int main(int argc, char** argv) {
    ev_default_loop(EVBACKEND_SELECT);
    while (1) {
        test_main();
        CHECK(fprintf(stderr, "."));
    }
}
_______________________________________________
libev mailing list
libev@lists.schmorp.de
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to