I’m coding my application in C++ on Linux. C++ has a function called ‘system’ to execute a programme.
I try to open the gnome-system-monitor from C++ like this:
system("gnome-system-monitor");
However, the thread of my application blocks when I call this ‘system’ function until I close the window of gnome-system-monitor.
Any other ways to open a process from file without blocking the caller process?
The classic way, which works on any Linux or otherwise POSIX-based system, is
(with error handling omitted from this example.) This (a) creates a new process, (b) in that new process, runs “gnome-system-monitor” after searching the PATH environment variable to find such a command, (c) passes it the name “gnome-system-monitor” as argv[0] and no other arguments. In the parent, once the new process is created it barrels on ahead without waiting for any result.
See the man pages for
forkandexeclpfor more details.