Hello,

I have a small app that uses pipes to do some basic client / server communication, just for testing purposes.

Well, when the server is run before the client, it works fine. However, if the client is run before the server, there are problems. To solve this I wanted to start the server from inside the client, if the client sees that there's no server.

This can possibly be done using fork and exec (exec to run the server binary file, replacing the child process's image.

if ( server_pipe == -1 ) {
   if ( fork == 0 ) {
      /* run exec function to start the server */
   }
}

I have been trying to do so, without sucess. I think that scheduling issues may affect the ability to run one from the other - because there are loops both in the server and in the client, that wait for input.

Is this possible or this there another better way to do it?

Thanks for your help.

I would think that if there's no server, that's a fatal error for the client. Since this is for testing purposes, why bother with an elaborate workaround when you can simply make sure that you run the server first?

I would think that if there's no server, that's a fatal error for the client. Since this is for testing purposes, why bother with an elaborate workaround when you can simply make sure that you run the server first?

Testing and learning purposes (the teacher asked it ).

After investigating... (ps -xua)

* the server does get started (appears on process list using ps -xua)
* that processe's state is S (sleeping)

Any ideas?

Thanks.

It's working.

Pretty much the same, just inserted a pausing section / call to wait for the server before trying to reopen the pipe.

Thanks.

This article has been dead for over six months. Start a new discussion instead.