"sridhar" <gsridhar78>wrote:
> I am sending request to exicute a script from a client
> machine(solaris 8) to server machine(linux) thru my Client.c and
> Server.c programs. If i send one connection at a time immediately
> returns the output. If there more than one request or connection(ie to
> execute more than one script at a time).. it takes time to return the
> output. This problem is only in Linux Platform.. It works perfectly in
> Solaris Environment.I am sending client and server programs as below
> client program
.... snipped out
> Server program
.... big parts snipped out
> void sigchld_handler(int s)
> {
> while(wait(NULL) > 0);
> }
> int main(void)
> /************************************************** **********
> ************************************************** ***********/
> {
> struct sigaction sa;
> sa.sa_handler = sigchld_handler; // reap all dead processes
> sigemptyset(&sa.sa_mask);
> sa.sa_flags = SA_RESTART;
> if (sigaction(SIGCHLD, &sa, NULL) == -1) {
> strcpy(msg,"Sigaction");

Hi sridhar,

You've introduced a signal-handler within the server-code, to clean up
all terminated child-processes. (This is a good idea.)

You've designed this signal-handler to be able to get rid of more than
only a single child...by looping in the while()-loop ... (another good

But, to my knowledge, wait() will return imediately, if ...
... the exit-code of a child is available
... there is no more child left
... a signal interrupts it
wait() will block, if there are one ore more child-processes running.

Depending on the run-time-needs of the childs, the server (holding
the listener socket) might be caught in this while-loop,
if more than one child is executed, and the first child terminates.

A good idea might be to use waitpid() instead of wait().
waitpit() offers more flexibility ...
you would use it with the pid-param set to -1 to have the
same functionality as wait() has got, but you would use it
with option=WNOHANG
In this case, waitpit() doesn't block, if no actual exit-code
is available, but children are still executed.

regards ... rainer