1

Is there any way how to run multiple instances of the same program in c++ ? Let's say for example you have a simple card game and you want to run it 3 times. Something like in GUI where you click on New Game button and it opens one instance of a game where you can play and then you click on New Game button again and it opens another instance (another window) of a game where you can play independently.

I'd like to know if it is possible to perform something like this in a console application ( like one window with more panels or something like that ?). Thank you for your replies.

Thank you guys for your replies, but it should be able to run it either on Linux or Windows. That's way i was asking about for example one windows with more panels if so. It's like ,it should be able to play up to for example 4 games simultaneously. If only one game is played, the graphics interface area will only contain this game (like one playing board). If more than one game is played, the graphical interface area will be divided into 4 tiles, each for one game (playing board). Unused tiles will not contain anything and the number of played games can be changed at run time. In GUIit shouldn't (guessing) be that hard, but I'm not still sure about CLI version

Arey Jeremy
  • 67
  • 1
  • 8
  • 1
    Is it possible? Yes. – Algirdas Preidžius Apr 24 '17 at 20:24
  • Its possible. `int main(int argc, char** argv)` provides the current exceutable path. Then use system() to call it. –  Apr 24 '17 at 20:28
  • There is nothing out of the box like that in C++, one would have to turn to operating system specific libraries for such operations, and even then they are not necessarily particularly easy to do (well admittedly I don't really know myself..) I like the question though, so I hope someone can elaborate better on this, maybe you get a better result if you ask a new question where you are more specific about which operating system you want to develop this for. – mous Apr 24 '17 at 20:32
  • @mutex36 that would not open a new terminal window would it? – mous Apr 24 '17 at 20:33
  • http://stackoverflow.com/questions/15435994/how-do-i-open-an-exe-from-another-c-exe Note: as suggested switch to WinAPI functions such as CreateProcess() –  Apr 24 '17 at 20:34
  • @mutex36 again, CreateProcess() doesn't create a new terminal does it? The OP seems to want the new program to run in another window. I would in that sense think that the ShellExecute() solution in the thread you posted seems more promising, though I haven't tried that.. These solutions are also assuming that the OP is developing for windows. – mous Apr 24 '17 at 20:47
  • 1
    There is a `CREATE_NEW_CONSOLE` flag. https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx –  Apr 24 '17 at 20:50
  • @mutex36 Cool :) – mous Apr 24 '17 at 20:51
  • The power of google :) Didn't know this either. –  Apr 24 '17 at 20:52

2 Answers2

1

Just start 3 processes, for example:

for(int i = 0; i < 3; i++)
  system("path_to_your_program");

It starts command in system command processor(bash/cmd.exe/etc). Or use system calls.

devalone
  • 535
  • 6
  • 21
0

That is OS dependent. Pretty much all currently support multiple processes so you'd just run your program 3 times.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125