Nuno Carvalho wrote:

>  One question:
> 
>   i'm using the usually forking "scheme":
> 
>   if((pid=fork())==0)  /* child process */
>   {
>     ....
>   }else{         /* parent process */
>    
>    
>   }
> 
>  If i put on parent process:
> 
>   wait(NULL) - it doesn't do what I want(for I get messages for user #2,
> user #1 need to disconnect - confused !? )

wait() will wait for a child process to terminate, and return the pid
of the child which terminated. You probably shouldn't be calling
wait() within the main loop of the parent process (as it will block),
although calling it from within a SIGCHLD handler should be OK.

>   waitpid(pid, NULL, 4) - I don't know understand third argument so I
> wrote 4 ; but it works as i want! :)

4 isn't a valid option. You should probably be using something like:

        pid = waitpid(0, NULL, WNOHANG);
        if (pid < 0)
                perror("waitpid");
        if (pid > 0)
                connection_count--;

>   otherwise if I don't put wait() neither waitpid() function it works
> as i want!:) What should i do ? User waitpid or just don't put
> anything ?

waitpid() is the only reliable way to keep track of when child
processes terminate. Counting SIGCHLD signals won't work if multiple
children terminate in quick succession, as the number of SIGCHLD
signals you receive may be less than the number of children which
terminated.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to