Sockets, system calls and wait() interaction problem

Sockets, system calls and wait() interaction problem

Post by Jim Stelzi » Wed, 20 Dec 1995 04:00:00



Hi,

I have a socket-based client-server application that acts as follows:

Client-side
-----------
1. Client sends "task" data to server.
2. Client waits for results from server.
3. Client receives results and prints them to a file.
4. Completes.

Server-side
-----------
1. Server waits for clients to connect.
2. Server receives "task to perform" data from client.
3. Server forks:
   (a) Child performs the task via a system() call.
       and returns data to client.
   (b) Parent loops back (1.) and waits for the next
       task request.

Problem
-------
Without performing a "WAIT" on the child process, zombie/defunct
processes get created. This will eventually overflow the file
descriptor table (true???) as each time.

If I do a wait() explicitly, only one request can be running
concurrently at one time.

So, I have written a signal-handler routine "do_wait()" to
perform the wait(). Of course since the child process performs
a system call to execute the task, the child code needs to
revert to the default signal handler or else system() will
return an ECHILD(10) error. (It took me a while to figure that
one out --> why the hell was the system command working correctly
and ouputting all the correct information but a "-1" was being
returned!!!)

Anyways, after all that, I am now getting an error:

        "accept failed: Interrupted system call"

==>   [EINTR] The call was interrupted by a signal before a valid
              connection arrived.

So, I am stuck with the dilemma of HOW DO I PREVENT THE CREATION
OF DEFUNCT PROCESSES WHILE ALLOWING CONCURRENT PROCESSES TO RUN??

Any help is appreciated.

Regards,
Jim

=====================================================================
Jim Stelzig                      |
ESN 393-1274                     | Recovery-Tools Support

 
 
 

Sockets, system calls and wait() interaction problem

Post by Kurt Fran » Thu, 21 Dec 1995 04:00:00


|> Hi,
|>
|> I have a socket-based client-server application that acts as follows:
|>
|> Client-side
|> -----------
|> 1. Client sends "task" data to server.
|> 2. Client waits for results from server.
|> 3. Client receives results and prints them to a file.
|> 4. Completes.
|>
|> Server-side
|> -----------
|> 1. Server waits for clients to connect.
|> 2. Server receives "task to perform" data from client.
|> 3. Server forks:
|>    (a) Child performs the task via a system() call.
|>        and returns data to client.
|>    (b) Parent loops back (1.) and waits for the next
|>        task request.
|>
|> Problem
|> -------
|> Without performing a "WAIT" on the child process, zombie/defunct
|> processes get created. This will eventually overflow the file
|> descriptor table (true???) as each time.
|>
|> If I do a wait() explicitly, only one request can be running
|> concurrently at one time.
|>
|> So, I have written a signal-handler routine "do_wait()" to
|> perform the wait(). Of course since the child process performs
|> a system call to execute the task, the child code needs to
|> revert to the default signal handler or else system() will
|> return an ECHILD(10) error. (It took me a while to figure that
|> one out --> why the hell was the system command working correctly
|> and ouputting all the correct information but a "-1" was being
|> returned!!!)
|>
|> Anyways, after all that, I am now getting an error:
|>
|>   "accept failed: Interrupted system call"
|>
|> ==>   [EINTR] The call was interrupted by a signal before a valid
|>               connection arrived.
|>
|> So, I am stuck with the dilemma of HOW DO I PREVENT THE CREATION
|> OF DEFUNCT PROCESSES WHILE ALLOWING CONCURRENT PROCESSES TO RUN??
|>
|> Any help is appreciated.
|>
|> Regards,
|> Jim
|>            
|> =====================================================================
|> Jim Stelzig                      |
|> ESN 393-1274                     | Recovery-Tools Support

use waitpid() with the nohang flag or use wait3()
(or wait4() if it supported on your machine)

kf

--

 
 
 

Sockets, system calls and wait() interaction problem

Post by Byung-Gyu Cha » Thu, 21 Dec 1995 04:00:00


Zombie(defunct process) problem. The solution is very simple.

On SysV,

#include <signal.h>
signal(SIGCHLD, SIG_IGN); /* somewhere in initialization part of main() */

On BSD,

#include <signal.h>
void sigign()
{
    wait(0);
    signal(SIGCHLD, sigign);

Quote:}

signal(SIGCHLD, sigign); /* somewhere in intialization part of main() */

I typed the contents in P.195-196, _UNIX Distributed Programming_
by Chris Brown.

Hope this help.

: Hi,

: I have a socket-based client-server application that acts as follows:

: Client-side
: -----------
: 1. Client sends "task" data to server.
: 2. Client waits for results from server.
: 3. Client receives results and prints them to a file.
: 4. Completes.

: Server-side
: -----------
: 1. Server waits for clients to connect.
: 2. Server receives "task to perform" data from client.
: 3. Server forks:
:    (a) Child performs the task via a system() call.
:        and returns data to client.
:    (b) Parent loops back (1.) and waits for the next
:        task request.

: Problem
: -------
: Without performing a "WAIT" on the child process, zombie/defunct
: processes get created. This will eventually overflow the file
: descriptor table (true???) as each time.

: If I do a wait() explicitly, only one request can be running
: concurrently at one time.

: So, I have written a signal-handler routine "do_wait()" to
: perform the wait(). Of course since the child process performs
: a system call to execute the task, the child code needs to
: revert to the default signal handler or else system() will
: return an ECHILD(10) error. (It took me a while to figure that
: one out --> why the hell was the system command working correctly
: and ouputting all the correct information but a "-1" was being
: returned!!!)

: Anyways, after all that, I am now getting an error:

:       "accept failed: Interrupted system call"

: ==>   [EINTR] The call was interrupted by a signal before a valid
:               connection arrived.

: So, I am stuck with the dilemma of HOW DO I PREVENT THE CREATION
: OF DEFUNCT PROCESSES WHILE ALLOWING CONCURRENT PROCESSES TO RUN??

: Any help is appreciated.

: Regards,
: Jim
:            
: =====================================================================
: Jim Stelzig                      |
: ESN 393-1274                     | Recovery-Tools Support

--
     --== %%%%%%__      Chang, Byung-Gyu
     -==  _+----||      Dept. of CS, Korea Advanced Institute of Science
    =     \_     |---.  and Technology, Taejon, Korea, 305-701
 chitos       .----"" Dorm.   : +82 42-869-5990
 CHITOS   .----"""'      URL     : http://ara.kaist.ac.kr/~chitos/

 
 
 

1. Question: Problem with socket, socket system call returns 0

Hi,
   Ok my problem is this I have tried to bind a socket but the bind
system call
return -1 and errno is set to 88 (it is not a valid socket descriptor).
Debugging my piece of code I have discovered that before the socket
system call returns 0. Is this a valid socket
descriptor ? I' m working as not root user and I have tried to bind the
socket on different ports for example 6969 etc..
The piece of code is something like this:

#include<stdio.h>
......
.....
sockaddr_in addr;

int main() {
    .......
    ........

    if ((sock = (AF_INET, SOCK_STREAM, 0))  ==  -1) {
       fprintf(stderr, "Socket creation error errno is %i\n", errno);
       return -1;
   }
   /* from now sock is = 0 */

   addr.sin_family = AF_INET;
   addr.sin_port = htons(6969);
   addr.sin_addr.s_addr = INADDR_ANY;
   bzero(&(addr.sin_zero), 8);

   if ((bind(sock, (struct sockaddr *)&addr, sizeof(sockaddr_in))) ==
-1) {
       fprintf(stderr, "Binding error errno is %i\n", errno);
       return -1;
     /* Here the program exit with errno set to 88 */
   }

    return 0;

Thanks to everyone can help me

            Cris

2. 2 modems to provide aggregate bandwidth possible? (no multilink)

3. Problem understanding wait system call

4. running x-application via linux & ppp connection

5. fork,exec and wait and wait and wait and wait

6. Xfree86

7. Problem with socket system call on a Linux box

8. Where is snmpdx invoked?

9. Wait System call

10. question on wait() system call on Linux

11. system call to wait for updated file?

12. SIGCHLD and the "wait" system call

13. wait() system call, child_processes