Spawn a child process, given a vector of arguments


#include <process.h>

int spawnv( int mode, 
            const char * path, 
            char * const argv[] );


BlackBerry 10.0.0


How you want to load the child process, and how you want the parent program to behave after the child program is initiated:
  • P_WAIT — load the child program into available memory, execute it, and make the parent program resume execution after the child process ends.
  • P_NOWAIT — execute the parent program concurrently with the new child process.
  • P_NOWAITO — execute the parent program concurrently with the new child process. You can't use wait() to obtain the exit code.
  • P_OVERLAY — replace the parent program with the child program in memory and execute the child. No return is made to the parent program. This is equivalent to calling the appropriate exec*() function.
The full path name of the executable.
A pointer to an argument vector; this argument can't be NULL. The value in argv[0] can't be NULL, and should represent the filename of the program being loaded. The last member of argv must be a NULL pointer.



Use the -l c option to qcc to link against this library. This library is usually included automatically.


The spawnv() function creates and executes a new child process, named in path with the NULL-terminated list of arguments in the argv vector. This function calls spawnvpe().

  • In order to create a child process, your process must have the PROCMGR_AID_SPAWN ability enabled. For more information, see procmgr_ability().
  • If the new child process is a shell script, the first line must start with #!, followed by the path of the program to run to interpret the script, optionally followed by one argument. The script must also be marked as executable. For more information, see " The first line " in the Writing Shell Scripts chapter of the BlackBerry 10 OS User's Guide.

The spawnv() function isn't a POSIX 1003.1 function, and isn't guaranteed to behave the same on all operating systems. It calls spawnve() before calling spawn(). For greater portability, use posix_spawn().

Most of the spawn*() functions do a lot of work before a message is sent to procnto :

Diagram showing how the spawn functions are related. spawn() spawnve() spawnl() spawnle() spawnp() spawnvpe() spawnlpe() spawnvp() spawnlp()

The child process inherits the parent's environment. The environment is the collection of environment variables whose values that have been defined with the export shell command, the env utility, or by the successful execution of the putenv() or setenv() function. A program may read these values with the getenv() function.

A parent/child relationship doesn't imply that the child process dies when the parent process dies.


The spawnv() function's return value depends on the mode argument:

mode Return value
P_WAIT The exit status of the child process. For information about macros that extract information from this status, see " Status macros " in the documentation for wait().
P_NOWAIT The process ID of the child process. To get the exit status for a P_NOWAIT process, you must use the waitpid() function, giving it this process ID.
P_NOWAITO The process ID of the child process, or 0 if the process is being started on a remote node. You can't get the exit status of a P_NOWAITO process.

If an error occurs, -1 is returned ( errno is set).


The number of bytes used by the argument list of the new child process is greater than ARG_MAX bytes.
Search permission is denied for a directory listed in the path prefix of the new child process or the new child process's file doesn't have the execute bit set.
Insufficient resources available to create the child process.
An error occurred duplicating open file descriptors to the new process.
The mode is P_WAIT, and the spawned process terminated before the call to waitpid() was completed.
One of the buffers specified in the function call is invalid.
The function was interrupted by a signal.
An argument is invalid (e.g. arg0 is NULL, or the value of mode isn't valid).
Too many levels of symbolic links or prefixes.
Insufficient resources available to load the new executable image or to remap file descriptors in the child process.
The length of path exceeds PATH_MAX or a pathname component is longer than NAME_MAX.
The file identified by the path argument is empty, or one or more components of the pathname of the child process don't exist.
The child process's file has the correct permissions, but isn't in the correct format for an executable.
Insufficient memory available to create the child process.
The spawnv() function isn't implemented for the filesystem specified in path.
A component of the path prefix of the child process isn't a directory.
The calling process doesn't have the required permission (see procmgr_ability()), or an underlying call to mmap() failed because it attempted to set PROT_EXEC for a region of memory covered by an untrusted memory-mapped file.
The text file that you're trying to execute is busy (e.g. it might be open for writing).


Run myprog as if a user had typed:

myprog ARG1 ARG2

at the command-line:

#include <stddef.h>
#include <process.h>

char *arg_list[] = { "myprog", "ARG1", "ARG2", NULL };
spawnv( P_WAIT, "myprog", arg_list );

The program is found if myprog is in the current working directory.



Cancellation point Read the Caveats
Interrupt handler No
Signal handler No
Thread Yes


If mode is P_WAIT, this function is a cancellation point.

Last modified: 2014-11-17

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus