Process creation
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()
Using fork() in a multithreaded processin the
Processes and Threadschapter of Getting Started with the QNX OS.
There are several versions of spawn*() and exec*(); the asterisk represents one to three letters, where:
l
orv
(one is required) indicates the way the process parameters are passedp
(optional) indicates that the PATH environment variable is searched to locate the program for the processe
(optional) indicates that the environment variables are being passed
For details on each of these functions, see their entries in
the QNX OS C Library Reference, as well as the
Processes and Threads
chapter of Getting Started with the QNX OS.
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 OS 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.