NSPR Reference Previous Contents Next |
NSPR does not provide an equivalent of the Unix fork()
. The newly-created
process executes its program from the beginning. A new process can inherit
specified file descriptors from its parent, and the parent can redirect the standard
I/O streams of the child process to specified file descriptors.
Note that the functions described in this chapter are not available for MacOS or Win16 operating systems.
Process Management Types and Constants
Process Management Functions
#include <prproces.h>
typedef struct PRProcess PRProcess;
PRProcess
structure identifies a process.
#include <prproces.h>
typedef struct PRProcessAttr PRProcessAttr;
PRProcessAttr
into PR_CreateProcess
when you create a new
process, specifying information such as standard input/output redirection and file
descriptor inheritance.
Setting the Attributes of a New Process
Creating and Managing Processes
PR_NewProcessAttr
PR_ResetProcessAttr
PR_DestroyProcessAttr
PR_ProcessAttrSetStdioRedirect
PR_ProcessAttrSetCurrentDirectory
PR_ProcessAttrSetInheritableFD
#include <prproces.h>
PRProcessAttr *PR_NewProcessAttr(void);
PRProcessAttr
structure that specifies the attributes of
a new process, then returns a pointer to the structure. The new PRProcessAttr
structure is initialized with these default attributes:
#include <prproces.h>
void PR_ResetProcessAttr(PRProcessAttr *attr);
attr
|
A pointer to the process attributes structure to be reset.
|
PRProcessAttr
structure can be reused to create many new
processes. Before using it to create a different process, re-initialize the structure
with a call to PR_ResetProcessAttr
.
#include <prproces.h>
void PR_DestroyProcessAttr(PRProcessAttr *attr);
attr
|
A pointer to the process attributes structure to be destroyed.
|
attr
becomes an invalid pointer and should not
be passed to other functions.
#include <prproces.h>
void PR_ProcessAttrSetStdioRedirect (
PRProcessAttr *attr,
PRInt32 stdioFd,
PRFileDesc *redirectFd);
attr
|
A pointer to the process attributes structure.
|
stdioFd
|
A standard I/O stream. Possible values are:
|
redirectFd
|
A pointer to a file descriptor.
|
#include <prproces.h>
PrStatus PR_ProcessAttrSetCurrentDirectory (
PRProcess *attr,
const char *dir);
attr
|
A pointer to the process attributes structure.
|
dir
|
The pathname of the current working directory for the new process.
|
PR_SUCCESS
; otherwise, PR_FAILURE
. Retrieve the reason for the
failure by calling PR_GetError
.
The runtime copies the pathname and maintains the copy. The function fails and
the error PR_OUT_OF_MEMORY_ERROR
occurs when NSPR cannot make a copy of the
string dir
.
#include <prproces.h>
void PR_ProcessAttrSetInheritableFD(
PRProcess *attr,
PRFileDesc *fd,
const char *name);
attr |
A pointer to the process attributes structure.
|
fd |
A pointer to the file descriptor to be inherited by the process.
|
name |
A pointer to the name for the inherited file descriptor.
|
fd
, which is given the string name
name
. The new process can get the inherited file descriptor by specifying the string
name to PR_GetInheritedFileDesc.
PR_CreateProcess
PR_DetachProcess
PR_WaitProcess
PR_KillProcess
#include <prproces.h>
PRProcess *PR_CreateProcess(
const char *path,
char *const *argv,
char *const *envp,
const PRProcessAttr *attr
PRProcess
structure representing the new
process. On failure, returns NULL
. Retrieve the reason for the failure by calling
PR_GetError
.
PR_CreateProcess()
creates a new process that executes the file specified in
argv[0]
, with the specified commmand-line arguments and environment. The
specified attribute structure determines the I/O redirection and file descriptor
inheritance of the new process.
The newly-created process must be either detached (PR_DetachProcess
) or reaped
(PR_WaitProcess
), otherwise the memory for its PRProcess
structure is not
reclaimed and results in memory leaks.
This function can fail due to illegal access (permissions), invalid arguments, or insufficient resources.
#include <prproces.h>
PRStatus PR_DetachProcess(PRProcess *process);
process
|
A pointer to the nondetached process to be detached.
|
PR_SUCCESS
; otherwise, PR_FAILURE
. Retrieve the reason for the
failure by calling PR_GetError
.
process
becomes an invalid
pointer and should not be passed to other functions.
#include <prproces.h>
PRStatus PR_WaitProcess (
PRProcess *process,
PRInt32 *exitCode);
process
|
A pointer to the nondetached process whose termination you want to
wait for.
|
exitCode
|
A pointer to a pre-allocated location to contain the exit code of the
process. Can be NULL .
|
PR_SUCCESS
; otherwise, PR_FAILURE
. Retrieve the reason for the
failure by calling PR_GetError
.
PR_SUCCESS
. If
exitCode
is not NULL
, the variable to which it points contains the exit status code of
process
.
#include <prproces.h>
PRStatus PR_KillProcess(PRProcess *process);
process
|
A pointer to the process to be killed.
|
PR_SUCCESS
; otherwise, PR_FAILURE
. Retrieve the reason for the
failure by calling PR_GetError
.
NOTE: It is not clear whether this function is useful, or that it can be implemented everywhere.
PRFileDesc * PR_GetInheritedFD(const char *name);
The newly created process can use PR_GetInheritedFileDesc to get the inherited file descriptor with the name name. The name is given by its parent process. The parent and child must have some prearranged agreement on the names of inherited file descriptors. <<
Last Updated May 18, 2001