[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] how to handle SIGCHLD before going into dispatch
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] how to handle SIGCHLD before going into dispatch
- From: Yee Keat Phuah <ykphuah@xxxxxxxxx>
- Date: Fri, 10 Aug 2012 23:06:55 +0800
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Fri, 10 Aug 2012 11:06:13 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=zTi9vJ6yp5sj7oESBSN0isSuLT39NPv45ad5hhHqW14=; b=0ijspU71CYNhFkarBvApp3VQwHBLrSb1gzHzGmM1i1hVtKZHU/9X3f6bBU1Di6LHL0 ejwXIe0N/N+SKfJVKz9pZov3clw1DTMn8t99KY6k1Nz1hLjTlQ4sJRPIi71owQdrmJvK RCr2pnQzFyKkxK9Es0Y9FTHV1bD+k9mEB8d7JSgqzmJ5DFV3CBJZFBlYsi79xdZJHucS ZcNThVFdWXzwU8/Ugf/oQR6Bcky+T3x0slnv2nXvnuejwE10XjNz7stHun8Epr4Hh5Y9 FuwSo0v0aXssZm4pck1EhoJA7ogIq8fYrzTLtN+uIWcr1XRn6w4uacWoK48XWfwWEQZ9 p57g==
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
I have a piece of code that does a fork, and the parent goes into the
event_dispatch loop while the child does something. The child will
exit at some point of time so I will need to attach a SIGCHLD handler
into the event_base (I assume that I shouldn't be calling
event_base_loopexit from a standard unix signal handler).
There's a problem when the child exits too fast, right after I do the
evsignal_new, but before going into the dispatch loop. To simulate
this, I have created a test program as follow, the child basically
just does nothing and exits (similiar with what my program does
sometimes), and the parent does a couple of things after forking,
before calling evsignal_new, and then do some other things again
(adding more handlers), to simulate this, I have added a sleep 1 into
the code.
In Linux, this piece of code seems to work properly, but in Solaris 10
Intel (libevent 2.0.6rc), it gives me a warning:
evsig_handler: received signal 18, but have no base configured
The effect is that the sigchld is not processed, and the loop is not exited.
How do I handle this case in Solaris 10?
==== start code ====
#include <signal.h>
#include "event.h"
static struct event_base *base = NULL;
static struct event *signal_event_chld;
static void child_signal_cb(evutil_socket_t fd, short event, void *arg)
{
struct timeval tv;
fprintf(stderr, "got sigchild\n");
tv.tv_usec = 500000;
tv.tv_sec = 0;
event_base_loopexit(base, &tv);
}
void do_parent()
{
base = event_base_new();
if (base==NULL) {
perror("event_base");
}
signal_event_chld = evsignal_new(base, SIGCHLD, child_signal_cb, NULL);
evsignal_add(signal_event_chld, NULL);
sleep(1);
event_base_dispatch(base);
printf("event_base_dispatch done\n");
}
int main()
{
pid_t pid;
pid = fork();
switch (pid) {
case -1:
perror("fork");
return -1;
break;
case 0:
break;
default:
fprintf(stderr, "forked child:%ld\n", (long)pid);
do_parent();
break;
}
return 0;
}
==== end code ====
--
Cheers,
Phuah Yee Keat
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.