The process manager component of procnto is
responsible for process creation. If a process wants to
create another process, it makes a call to one of the
process-creation functions, which then effectively sends a
message to the process manager.
Here are the process-creation functions:
- exec*() family of functions:
execl(),
execle(),
execlp(),
execlpe(),
execv(),
execve(),
execvp(),
execvpe()
- fork()
- forkpty()
- popen()
- posix_spawn()
- spawn*() family of functions:
spawn(),
spawnl(),
spawnle(),
spawnlp(),
spawnlpe(),
spawnp(),
spawnv(),
spawnve(),
spawnvp(),
spawnvpe()
- system()
Note:
It's possible to call
fork() from a multithreaded process, but it can be very difficult
to do so safely, so we recommend that you call it only from single-threaded processes.
For more information, see
Using fork() in a multithreaded process
in the
Processes and Threads chapter of
Getting Started with QNX Neutrino.
There are several versions of spawn*() and exec*();
the asterisk represents one to three letters, where:
- l or v (one is required) indicates the way the process parameters are passed
- p (optional) indicates that the PATH environment variable is searched to locate
the program for the process
- e (optional) indicates that the environment variables are being passed
For details on each of these functions, see their entries in
the QNX Neutrino C Library Reference, as well as the
Processes and Threads
chapter of Getting Started with QNX Neutrino.
Here we'll
mention some of the things common to many of them.
When you start a new process, it replaces the existing process if:
- You specify POSIX_SPAWN_EXEC in the extended flags before you call
posix_spawn().
In spite of the name, this flag is a QNX Neutrino extension.
- You specify P_OVERLAY when calling one of the
spawn* functions.
- You call one of the exec* routines.
The calling thread in the existing process is suspended while the new process
executes (control continues at the point following the place where the
new process was started) in the following situations:
- You specify P_WAIT when calling one of the
spawn* functions.
- You call system().
Note:
The system() function involves a lot of overhead, so you should avoid
using it when you just want to create a process.
You should use it only when you need a shell that can parse a complex command line,
for example, involving pipes or the redirection of file descriptors.