Im writing a small fastcgi app and i want to make it work as many listeners like this:
It listens as 4 workers, but i wanna it work as 5 workers, so i do this like:
By the plan, it must fork 5 times(numforks=5) and stay manage this workers. So it should be 6 processes, 5 of them(workers) listening.. Each worker must open socket on same unix socket path, listening queries at same time, but....
This "Address already in use" shows sometimes, so i see only 4 listeners in `sockstat -l`..
Sometimes it gives only 3 listeners (2 times "already in use") or 5 listeners (all ok).
Took algorythm from FCGI:rocManager perl module, but cant get it to work correctly...
I guess there is a bug somewhere, it should not work time-to-time =) Cant find whats problem.. Thanks for help
Code:
# sockstat -l
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
alt fcgi-serve 93657 3 stream /tmp/fcgi-server.sock
alt fcgi-serve 93656 3 stream /tmp/fcgi-server.sock
alt fcgi-serve 93655 3 stream /tmp/fcgi-server.sock
alt fcgi-serve 93653 3 stream /tmp/fcgi-server.sock
Code:
while(1) {
while( child_list.size() < numforks ) {
pid_t pid = fork();
if( pid == -1 ) {
// error
cout << "Fork fail" << endl;
exit(EXIT_FAILURE);
}else if( pid == 0 ) {
// child
worker_pid = getpid();
worker_served_count = 0;
return 0;
} else {
cout << "Child "<< pid << " forked"<<endl;
child_list.push_back(pid);
}
}
sleep(1);
}
// ...some code here...
// Open socket
int listen_socket = FCGX_OpenSocket(sock.c_str(), queue_len);
Code:
> ./fcgi-server
fork 5 times
Child 91862 forked
Child 91863 forked
Child 91864 forked
Child 91865 forked
Child 91866 forked
bind/listen: Address already in use
Sometimes it gives only 3 listeners (2 times "already in use") or 5 listeners (all ok).
Took algorythm from FCGI:rocManager perl module, but cant get it to work correctly...
I guess there is a bug somewhere, it should not work time-to-time =) Cant find whats problem.. Thanks for help