FreeBSD, fork() and zombies


 
Thread Tools Search this Thread
Top Forums Programming FreeBSD, fork() and zombies
# 1  
Old 03-18-2006
Data FreeBSD, fork() and zombies

i'm writing small http proxy server (accept client -> connect to remote proxy server -> recv client's request -> send to remote proxy server -> get responce from remote proxy server -> send answer to client -> close connection to client and to remote proxy server) and having problems with fork(). when connections come to local port, i'm forking them to process the request. but when there are many (100+) simaltenious connections, childs become to work slower and die in 2-20 seconds. i have no limits for simaltenious incoming connections. when child dies it sends SIGCHLD signal to the parent application, which has a handler:

static void sig_chld(int no) {
while (waitpid(-1, NULL, WNOHANG) > 0);
}

and a set up function:
static void install_sig_handlers(void) {
struct sigaction sig_act;

sig_act.sa_handler = sig_chld;
sig_act.sa_flags = 0;
sigfillset(&sig_act.sa_mask);
sigaction(SIGCHLD, &sig_act, NULL);

sig_act.sa_handler = SIG_IGN;
sig_act.sa_flags = 0;
sigemptyset(&sig_act.sa_mask);
sigaction(SIGPIPE, &sig_act, NULL);
}

this works fine on my FreeBSD 4.4 server for 1-100 simaltenious connections from clients. but it becomes wierd when 100+ connections come: zombies start leaving in memory and their number grows. after several minutes of work with 100+ connections server goes down with about 10000 zombies in memory and 0% cpu idle, and at the same time none of my processes (parent or childs) loads the server (by `ps -awx` results) - neither cpu, nor memory.

please help me to find correct decision for this problem. Thanx.
# 2  
Old 03-21-2006
Probably the correct solution would involve a much more complex design. But here is something easily implemented that might be worth a try. This freebsd man page says that freebsd supports the System V sigcld sematics. So just turn on SA_NOCLDWAIT and then no zombies should ever exist.
# 3  
Old 03-22-2006
Quote:
Originally Posted by Perderabo
Probably the correct solution would involve a much more complex design. But here is something easily implemented that might be worth a try. This freebsd man page says that freebsd supports the System V sigcld sematics. So just turn on SA_NOCLDWAIT and then no zombies should ever exist.
Thnx for advice, but
neither first construction nor second work properly - zombies still continue to stay Smilie

1st:
sig_act.sa_handler = SIG_IGN;
sig_act.sa_flags = SA_NOCLDWAIT;
sigemptyset(&sig_act.sa_mask);
sigaction(SIGCHLD, &sig_act, NULL);


2nd:
sig_act.sa_handler = SIG_IGN;
sig_act.sa_flags = SA_NOCLDWAIT;
sigfillset(&sig_act.sa_mask);
sigaction(SIGCHLD, &sig_act, NULL);
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help! Zombies

Hello, quick question: I have a zombie process listed with 'top' Could someone help me find out what it the PID is for it, so I can kill $PID. $ model 9000/800/rp3440 HP-UX bigassserver B.11.31 U 9000/800 3085785128 unlimited-user license thanks! System: bigassserver ... (23 Replies)
Discussion started by: olyanderson
23 Replies

2. UNIX for Dummies Questions & Answers

fork()

I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..? Thanks! (1 Reply)
Discussion started by: l flipboi l
1 Replies

3. Programming

Ways to eliminate Zombies?

what are the precautions to be taken care for avoiding zombie process ? (8 Replies)
Discussion started by: Gopi Krishna P
8 Replies

4. UNIX for Dummies Questions & Answers

Zombies

I had a problem deleting a zombie process. It refused to be killed. I even tried kill -9 process# but it refused. Any other way of killing it? (7 Replies)
Discussion started by: victorn
7 Replies

5. Programming

Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3

Hello there, My mulithreaded application (which is too large to represent the source code here) is crashing after installing FreeBSD 7.1-RELEASE/amd64. It worked properly on others machines (Dual Cores with 4GB of RAM - FreeBSD 6.2-RELEASE/i386). The current machine has 2x Core 2 Duo... (1 Reply)
Discussion started by: Seenquev
1 Replies

6. Programming

Fork and \n

Hi, I wrote a simple program for understanding the fork command. The code is as below int main(void) { fork(); printf("hi 1 \n"); fork(); printf("hi 2 \n"); fork(); printf("hi 3 \n"); } I am getting a variation in the number of times the printf is called if i remove the \n from each... (2 Replies)
Discussion started by: xyz123456
2 Replies

7. Programming

fork() help

Hi everybody, I wanna write a code to understand how fork works. my target -------------- -Parent creates a file(called temp) and writes into this file "1".Then it closes the file. -Then parent creates a child and wait until execution of this child ends. -Then child opens the same... (3 Replies)
Discussion started by: alexicopax
3 Replies

8. HP-UX

How can i kill Zombies

Hi All I need help, how can i kill zombies instead of rebooting the system. Regards System: sna Tue Apr 5 17:50:23 2005 Load averages: 0.05, 0.15, 0.22 168 processes: 157 sleeping, 5 running, 6 zombies Cpu states: CPU LOAD USER NICE... (5 Replies)
Discussion started by: cgege
5 Replies

9. UNIX for Dummies Questions & Answers

No zombies!

Is there a command that will automaticaly go through and kill all children when you try to kill the parent process. Thanks, David (3 Replies)
Discussion started by: nucca
3 Replies

10. UNIX for Dummies Questions & Answers

Zombies

Okay, I'm working within ansi C and Sun Solaris 7. I have a problem with zombies. I'm currently using the kill command to return the status of a process. How do I check for Zombie PIDs or the right function to return its PID from within a C program? (1 Reply)
Discussion started by: karpolu
1 Replies
Login or Register to Ask a Question