On Windows in C#, I can launch an external program from within my code by calling Process.Start()
, which starts the process and returns its ID. This is important because I am not forking my own process, and I might have to kill the process later.
I have looked at exec()
, fork()
and many other things under Linux in C++ but none of those do quite the same thing. For example, system()
blocks while the program runs, and fork()
duplicates my whole process just so I can run another task.
Can someone tell me what the equivalent is?
The way to start a new process on Linux is by using fork
and exec
. This you can wrap in your own System
class that holds the PID and provides methods to kill the process etc. An example of such a class is QProcess
from the Qt library.
Note: there's also the posix_spawn() and (Linux specific) clone() functions.