ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.133 by root, Sun Feb 24 06:50:16 2008 UTC vs.
Revision 1.134 by root, Sat Mar 8 07:04:56 2008 UTC

1454 1454
1455 1455
1456=head2 C<ev_child> - watch out for process status changes 1456=head2 C<ev_child> - watch out for process status changes
1457 1457
1458Child watchers trigger when your process receives a SIGCHLD in response to 1458Child watchers trigger when your process receives a SIGCHLD in response to
1459some child status changes (most typically when a child of yours dies). 1459some child status changes (most typically when a child of yours dies). It
1460is permissible to install a child watcher I<after> the child has been
1461forked (which implies it might have already exited), as long as the event
1462loop isn't entered (or is continued from a watcher).
1463
1464Only the default event loop is capable of handling signals, and therefore
1465you can only rgeister child watchers in the default event loop.
1466
1467=head3 Process Interaction
1468
1469Libev grabs C<SIGCHLD> as soon as the default event loop is
1470initialised. This is necessary to guarantee proper behaviour even if
1471the first child watcher is started after the child exits. The occurance
1472of C<SIGCHLD> is recorded asynchronously, but child reaping is done
1473synchronously as part of the event loop processing. Libev always reaps all
1474children, even ones not watched.
1475
1476=head3 Overriding the Built-In Processing
1477
1478Libev offers no special support for overriding the built-in child
1479processing, but if your application collides with libev's default child
1480handler, you can override it easily by installing your own handler for
1481C<SIGCHLD> after initialising the default loop, and making sure the
1482default loop never gets destroyed. You are encouraged, however, to use an
1483event-based approach to child reaping and thus use libev's support for
1484that, so other libev users can use C<ev_child> watchers freely.
1460 1485
1461=head3 Watcher-Specific Functions and Data Members 1486=head3 Watcher-Specific Functions and Data Members
1462 1487
1463=over 4 1488=over 4
1464 1489
1487 1512
1488The process exit/trace status caused by C<rpid> (see your systems 1513The process exit/trace status caused by C<rpid> (see your systems
1489C<waitpid> and C<sys/wait.h> documentation for details). 1514C<waitpid> and C<sys/wait.h> documentation for details).
1490 1515
1491=back 1516=back
1517
1518=head3 Examples
1519
1520Example: C<fork()> a new process and install a child handler to wait for
1521its completion.
1522
1523 ev_child cw;
1524
1525 static void
1526 child_cb (EV_P_ struct ev_child *w, int revents)
1527 {
1528 ev_child_stop (EV_A_ w);
1529 printf ("process %d exited with status %x\n", w->rpid, w->rstatus);
1530 }
1531
1532 pid_t pid = fork ();
1533
1534 if (pid < 0)
1535 // error
1536 else if (pid == 0)
1537 {
1538 // the forked child executes here
1539 exit (1);
1540 }
1541 else
1542 {
1543 ev_child_init (&cw, child_cb, pid, 0);
1544 ev_child_start (EV_DEFAULT_ &cw);
1545 }
1492 1546
1493 1547
1494=head2 C<ev_stat> - did the file attributes just change? 1548=head2 C<ev_stat> - did the file attributes just change?
1495 1549
1496This watches a filesystem path for attribute changes. That is, it calls 1550This watches a filesystem path for attribute changes. That is, it calls

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines