I can open a program in terminal using:
stringstream s;
s<<"./~/rajat/app -parameter";
system(s.str().c_str());
My app keeps on running in a terminal , what I want to do is shut down this app from inside the same program and open it again using new parameters. How to do this?
You can’t do this using
system. From (BSD)man 3 system:So your app will block until the completion or termination of the launched program.
You can get the behavior that you want by instead launching your program using
fork/exec– man pages here, and here. This is whatsystemis doing under the hood. You’ll launch the sub-process and maintain control in your app.Using
fork, you’ll get a process id for your launched process, and using that you can e.g. terminate the program usingkill– man page here – and re-launch the program.Look around for
fork/execexamples, there are probably more than a few on this site.