0

Background:

So I have client/server type of app rolled into the same executable.

What I want is if it fails to connect on the localhost, it should start itself (same executable, but with different parameters/command so to start the server). Then perhaps wait a bit and then try to connect again (only try once). This is different from, but similar, to fork()'ing (which I could have used, but fork() is not cross platform).

Question

I know boost::process can launch the process in a platform independent manner, but is there a way to obtain the path of the process so that to launch oneself (cross platform) ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
darune
  • 10,480
  • 2
  • 24
  • 62
  • 1
    I developed a "process monitor" functionality some years ago where a second process kept the first process "alive". So that works. But I understand you want your executable to "monitor and administrate" itself? It may be hard? I suppose you have to figure out a way to initiate a new process where your executable is no longer the parent (owner)?. Good luck :) – Kjell-Olov Högdahl Dec 10 '20 at 10:40
  • 1
    IMHO this should be one process (w/o restarting). Just implement in your main() simple state machine: [*] --> RunAsClient RunAsClient --> InitialLocalRun : failed InitialLocalRun --> RetryRunAsClient : timeout RetryRunAsClient --> LocalRun : failed – PiotrNycz Dec 10 '20 at 10:52
  • My main issue atm. is how to do a start the process, ie. how to get the full path to the execuatable ? – darune Dec 10 '20 at 11:14
  • FYI: [SO: Get path of executable](https://stackoverflow.com/a/1528493/7478597) – Scheff's Cat Dec 10 '20 at 12:10

0 Answers0