I’m trying to execute an external program from inside my Linux C++ program.
I’m calling the method system("gedit") to launch an instance of the Gedit editor. However my problem is while the Gedit window is open, my C++ program waits for it to exit.
How can I call an external program without waiting for it to exit?
You will need to use
forkandexecYou will also need to reap your child so as not to leave a zombie process.
In regards to zombie processes, you have a second option. It uses a bit more resources (this flavor forks twice), but the benefit is you can keep your wait closer to your fork which is nicer in terms of maintenance.
What this last flavor does is create a child, which in turns creates a grandchild and the grandchild is what exec’s your gedit program. The child itself exits and the parent process can reap it right away. So an extra fork but you keep all the code in one place.