Thread: anybody with experience using the wait() function?

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    7

    anybody with experience using the wait() function?

    I'm working on a program that forks into several processes. The main process becomes a server, and the child processes become clients. The clients basically request line numbers to a file until a certain limit is reached, and the server then quits. My problem is that as soon as the server reaches it's limit, it exits and the child processes also exit without printing out what they accomplished. When I try using the wait function, the system just hangs.
    I've tried using wait with the process ids as well. Am I missing something when I'm working with the wait function? Any ideas? Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Seems to me that your clients need to make a better job of detecting that the server has quit, rather than just quitting themselves in response.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    7
    You're probably right.. any ideas on how to set the client up to realize when the server has completed? Thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Look at the error status from reading the pipe (assuming you're using pipes).

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    7
    I'm using pipes.. how can I check on the error status? First time using c.. actually, first time working between processes like this. Thanks for the help.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > how can I check on the error status?
    RTFM would be a start - you must have done quite a lot of reading to get this far, just keep digging.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    7
    Well, I have been looking at the manual.. or on-line references, for that matter. I've been using the unix man cmds to try to find stuff. One of the clients closes up shop, and the server does too.. it's the other 2 clients that are left hanging around. Supposedly the read/write functions are supposed to return back with a negative value if they fail? Is that correct?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    That would be my first guess
    read is the only thing you're likely to be doing to a pipe when it's suddenly closed.

    Code:
    n = read( ... );
    if ( n == -1 ) {
      perror("read error");
    }
    Find out which error number is associated with the closure of the pipe, then code this in.

    You should still report any other read error as being unusual.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10:08 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM