Back to index

wims  3.65+svn20090927
Defines | Functions | Variables
fork.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MAX_FORK   1024
#define MAX_DELAY   1500 /* At most these seconds of execution */

Functions

void addfork (pid_t pid, int type)
void forkman (int kz)
void wait_children (void)

Variables

struct {
pid_t pid
time_t t
int type
int pad
forklist [MAX_FORK]
int forkcnt

Define Documentation

#define MAX_DELAY   1500 /* At most these seconds of execution */

Definition at line 21 of file fork.c.

#define MAX_FORK   1024

Definition at line 20 of file fork.c.


Function Documentation

void addfork ( pid_t  pid,
int  type 
)

Definition at line 31 of file fork.c.

{
    if(forkcnt>=MAX_FORK) {
       kill(pid,SIGKILL); return;
    }
    forklist[forkcnt].pid=pid;
    forklist[forkcnt].t=time(NULL);
    forklist[forkcnt].type=type;
    forkcnt++;
}

Here is the caller graph for this function:

void forkman ( int  kz)

Definition at line 43 of file fork.c.

{
    int delay, i, t, st;
    time_t now;
    delay=MAX_DELAY; 
    if(forkcnt>=MAX_FORK/2) delay=delay/5;
    if(forkcnt*4>=MAX_FORK*3) delay=delay/4;
    now=time(NULL);
    for(i=forkcnt-1; i>=0; i--) {
       if(now-forklist[i].t>delay) kill(forklist[i].pid,SIGKILL);
       t=waitpid(forklist[i].pid,&st,WNOHANG);
       if(t==0 || !WIFEXITED(st)) continue;
       memmove(forklist+i,forklist+i+1,forkcnt-1-i);
       forkcnt--;
    }
    if(kz) waitpid(-1,NULL,WNOHANG); /* kill zombies */
}

Here is the caller graph for this function:

void wait_children ( void  )

Definition at line 61 of file fork.c.

{
    time_t now;
    int i;
    do {
       now=time(NULL);
       for(i=0; i<forkcnt; i++) {
           if(forklist[i].type && forklist[i].t < now-MAX_DELAY) break;          
       }
       if(i>=forkcnt) return;
       sleep(1);
    }
    while(1);
}

Here is the caller graph for this function:


Variable Documentation

int forkcnt

Definition at line 29 of file fork.c.

struct { ... } forklist[MAX_FORK]