Fork and exec to run external needed app

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2005
Posts: 18
Reputation: Mr. is an unknown quantity at this point 
Solved Threads: 0
Mr. Mr. is offline Offline
Newbie Poster

Fork and exec to run external needed app

 
0
  #1
May 15th, 2005
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.

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

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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Fork and exec to run external needed app

 
0
  #2
May 15th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 18
Reputation: Mr. is an unknown quantity at this point 
Solved Threads: 0
Mr. Mr. is offline Offline
Newbie Poster

Re: Fork and exec to run external needed app

 
0
  #3
May 15th, 2005
Originally Posted by Dogtree
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 ).
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 18
Reputation: Mr. is an unknown quantity at this point 
Solved Threads: 0
Mr. Mr. is offline Offline
Newbie Poster

Re: Fork and exec to run external needed app

 
0
  #4
May 15th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 18
Reputation: Mr. is an unknown quantity at this point 
Solved Threads: 0
Mr. Mr. is offline Offline
Newbie Poster

Re: Fork and exec to run external needed app

 
0
  #5
May 16th, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC