Rev 10 | Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 10 | Rev 8155 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * You should have received a copy of the GNU General Public License |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 |
|
18 | /* fork management */ |
19 | 19 | ||
20 | #define MAX_FORK 1024 |
20 | #define MAX_FORK 1024 |
21 | #define MAX_DELAY 1500 /* At most these seconds of execution */ |
21 | #define MAX_DELAY 1500 /* At most these seconds of execution */ |
22 | 22 | ||
23 | struct { |
23 | struct { |
Line 37... | Line 37... | ||
37 | forklist[forkcnt].t=time(NULL); |
37 | forklist[forkcnt].t=time(NULL); |
38 | forklist[forkcnt].type=type; |
38 | forklist[forkcnt].type=type; |
39 | forkcnt++; |
39 | forkcnt++; |
40 | } |
40 | } |
41 | 41 | ||
42 |
|
42 | /* forklist management */ |
43 | void forkman(int kz) |
43 | void forkman(int kz) |
44 | { |
44 | { |
45 | int delay, i, t, st; |
45 | int delay, i, t, st; |
46 | time_t now; |
46 | time_t now; |
47 | delay=MAX_DELAY; |
47 | delay=MAX_DELAY; |
48 | if(forkcnt>=MAX_FORK/2) delay=delay/5; |
48 | if(forkcnt>=MAX_FORK/2) delay=delay/5; |
49 | if(forkcnt*4>=MAX_FORK*3) delay=delay/4; |
49 | if(forkcnt*4>=MAX_FORK*3) delay=delay/4; |
50 | now=time(NULL); |
50 | now=time(NULL); |
51 | for(i=forkcnt-1; i>=0; i--) { |
51 | for(i=forkcnt-1; i>=0; i--) { |
52 | if(now-forklist[i].t>delay) kill(forklist[i].pid,SIGKILL); |
52 | if(now-forklist[i].t>delay) kill(forklist[i].pid,SIGKILL); |
Line 63... | Line 63... | ||
63 | time_t now; |
63 | time_t now; |
64 | int i; |
64 | int i; |
65 | do { |
65 | do { |
66 | now=time(NULL); |
66 | now=time(NULL); |
67 | for(i=0; i<forkcnt; i++) { |
67 | for(i=0; i<forkcnt; i++) { |
68 | if(forklist[i].type && forklist[i].t < now-MAX_DELAY) break; |
68 | if(forklist[i].type && forklist[i].t < now-MAX_DELAY) break; |
69 | } |
69 | } |
70 | if(i>=forkcnt) return; |
70 | if(i>=forkcnt) return; |
71 | sleep(1); |
71 | sleep(1); |
72 | } |
72 | } |
73 | while(1); |
73 | while(1); |