Back to index

courier  0.68.2
Defines | Functions | Variables
testwait.c File Reference
#include "waitlib.h"
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

Go to the source code of this file.

Defines

#define NUMCHILDREN   100 /* Start 100 child processes */
#define INITCHILDREN   10 /* Start with these many child procs */

Functions

static void reap_child (pid_t p, int dummy)
static RETSIGTYPE sighandler (int sig)
static pid_t start_child ()
void foobar ()
int main ()

Variables

static unsigned started
static unsigned finished

Define Documentation

#define INITCHILDREN   10 /* Start with these many child procs */

Definition at line 17 of file testwait.c.

#define NUMCHILDREN   100 /* Start 100 child processes */

Definition at line 16 of file testwait.c.


Function Documentation

void foobar ( )

Definition at line 7 of file testwait2.c.

{
}

Here is the caller graph for this function:

int main ( )

Definition at line 56 of file testwait.c.

{
int    pipefd[2];
int    pipefd2[2];
char   c;

       if (pipe(pipefd) || pipe(pipefd2))
       {
              perror("pipe");
              exit(1);
       }

       signal(SIGCHLD, sighandler);

       started=finished=0;
       while (started < INITCHILDREN)
       {
              if (start_child() == 0)
              {
                     close(pipefd2[0]);
                     close(pipefd2[1]);
                     close(pipefd[1]);
                     if (read(pipefd[0], &c, 1) != 1)
                            ; /* Shut gcc up */
                     close(pipefd[0]);
                     _exit(0);
              }
       }
       close(pipefd2[1]);
       close(pipefd[0]);
       if (read(pipefd2[0], &c, 1) != 1)
              ; /* Shut gcc up */
       close(pipefd[1]);
       close(pipefd2[0]);

       while (started < NUMCHILDREN)
              if (start_child() == 0)
                     _exit(0);

       alarm(30);
       while (finished < started)
              foobar();
       exit(0);
}

Here is the call graph for this function:

static void reap_child ( pid_t  p,
int  dummy 
) [static]

Definition at line 21 of file testwait.c.

{
       ++finished;
}

Here is the caller graph for this function:

static RETSIGTYPE sighandler ( int  sig) [static]

Definition at line 26 of file testwait.c.

{
       wait_reap(&reap_child, &sighandler);
#if    RETSIGTYPE != void
       return (0);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static pid_t start_child ( ) [static]

Definition at line 34 of file testwait.c.

{
pid_t  p;

       wait_block();
       while ((p=fork()) == (pid_t)-1)
       {
              perror("fork");
              sleep(3);
       }
       ++started;
       if (p == 0)
       {
              wait_restore();
       }
       else
              wait_clear(&sighandler);
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

unsigned finished [static]

Definition at line 19 of file testwait.c.

unsigned started [static]

Definition at line 19 of file testwait.c.