944,161 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 11243
  • C++ RSS
May 15th, 2005
0

Fork and exec to run external needed app

Expand Post »
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.

C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Mr.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mr. is offline Offline
18 posts
since May 2005
May 15th, 2005
0

Re: Fork and exec to run external needed app

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?
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
May 15th, 2005
0

Re: Fork and exec to run external needed app

Quote 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 ).
Mr.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mr. is offline Offline
18 posts
since May 2005
May 15th, 2005
0

Re: Fork and exec to run external needed app

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.
Mr.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mr. is offline Offline
18 posts
since May 2005
May 16th, 2005
0

Re: Fork and exec to run external needed app

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.
Mr.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Mr. is offline Offline
18 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Ask a question
Next Thread in C++ Forum Timeline: c++ strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC