MyWebUniversity.com Home Page
 



OpenSolaris man pages main menu


Standard C Library Functions                      posixspawn(3C)



NAME
     posixspawn, posixspawnp - spawn a process

SYNOPSIS
     #include 

     int posixspawn(pidt *restrict pid, const char *restrict path,
          const posixspawnfileactionst *fileactions,
          const posixspawnattrt *restrict attrp,
          char *const argv[restrict], char *const envp[restrict]);


     int posixspawnp(pidt *restrict pid, const char *restrict file,
          const posixspawnfileactionst *fileactions,
          const posixspawnattrt *restrict attrp,
          char *const argv[restrict], char *const envp[restrict]);


DESCRIPTION
     The posixspawn() and posixspawnp() functions create a  new
     process  (child  process)  from the specified process image.
     The new process image is constructed from a regular  execut-
     able file called the new process image file.


     When a C program is executed as the result of this call,  it
     is entered as a C language function call as follows:

       int main(int argc, char *argv[]);



     where argc is the argument count and argv  is  an  array  of
     character pointers to the arguments themselves. In addition,
     the following variable

       extern char **environ;



     is initialized  as  a  pointer  to  an  array  of  character
     pointers to the environment strings.


     The argument argv is  an  array  of  character  pointers  to
     null-terminated  strings. The last member of this array is a
     null pointer and is not counted in argc. These strings  con-
     stitute  the  argument  list  available  to  the new process
     image. The value in argv[0] should point to a filename  that
     is  associated  with  the process image being started by the
     posixspawn() or posixspawnp() function.




SunOS 5.11          Last change: 20 Feb 2009                    1






Standard C Library Functions                      posixspawn(3C)



     The argument envp is  an  array  of  character  pointers  to
     null-terminated   strings.   These  strings  constitute  the
     environment for the new process image. The environment array
     is terminated by a null pointer.


     The number of bytes available for the child  process's  com-
     bined  argument and environment lists is {ARGMAX}, counting
     all character pointers,  the  strings  they  point  to,  the
     trailing null bytes in the strings, and the list-terminating
     null  pointers.  There  is  no  additional  system  overhead
     included in this total.


     The path argument to posixspawn() is a pathname that  iden-
     tifies the new process image file to execute.


     The file parameter to posixspawnp() is used to construct  a
     pathname  that identifies the new process image file. If the
     file parameter contains a slash character, the file  parame-
     ter  is used as the pathname for the new process image file.
     Otherwise, the path prefix for this file is  obtained  by  a
     search of the directories passed as the environment variable
     PATH. If this  environment  variable  is  not  defined,  the
     results of the search are implementation-defined.


     If fileactions is a null  pointer,  then  file  descriptors
     open  in  the  calling process remain open in the child pro-
     cess, except for those whose close-on-exec  flag  FDCLOEXEC
     is  set  (see  fcntl(2)).   For  those file descriptors that
     remain open, all attributes of the corresponding  open  file
     descriptions,  including  file  locks (see fcntl(2)), remain
     unchanged.


     If fileactions is not NUL, then the file descriptors  open
     in  the  child process are those open in the calling process
     as modified by the spawn file actions object pointed  to  by
     fileactions  and the FDCLOEXEC flag of each remaining open
     file descriptor after the spawn file actions have been  pro-
     cessed.  The  effective  order  of processing the spawn file
     actions are:

         1.   The set of open file descriptors for the child pro-
              cess  are initially the same set as is open for the
              calling process. All attributes of the  correspond-
              ing  open  file  descriptions, including file locks
              (see fcntl(2)), remain unchanged.

         2.   The signal mask, signal default or ignore  actions,



SunOS 5.11          Last change: 20 Feb 2009                    2






Standard C Library Functions                      posixspawn(3C)



              and  the effective user and group IDs for the child
              process are changed as specified in the  attributes
              object referenced by attrp.

         3.   The  file  actions  specified  by  the  spawn  file
              actions  object are performed in the order in which
              they were added to the spawn file actions object.

         4.   Any file descriptor that has  its  FDCLOEXEC  flag
              set (see fcntl(2)) is closed.


     The  posixspawnattrt  spawn  attributes  object  type   is
     defined  in  .  It contains at least the attributes
     defined below.


     If the POSIXSPAWNSETPGROUP flag is set in the  spawn-flags
     attribute  of the object referenced by attrp, and the spawn-
     pgroup attribute of the same object is  non-zero,  then  the
     child's  process  group  is as specified in the spawn-pgroup
     attribute of the object referenced by attrp.


     As a special case, if the POSIXSPAWNSETPGROUP flag is  set
     in  the  spawn-flags  attribute  of the object referenced by
     attrp, and the spawn-pgroup attribute of the same object  is
     set  to  zero, then the child will be in a new process group
     with a process group ID equal to its process ID.


     If the POSIXSPAWNSETPGROUP flag is not set in  the  spawn-
     flags  attribute  of the object referenced by attrp, the new
     child process inherits the parent's process group.


     If the POSIXSPAWNSETSCHEDPARAM flag is set in  the  spawn-
     flags  attribute  of  the  object  referenced  by attrp, but
     POSIXSPAWNSETSCHEDULER is not set, the new  process  image
     initially  has  the scheduling policy of the calling process
     with the  scheduling  parameters  specified  in  the  spawn-
     schedparam attribute of the object referenced by attrp.


     If the POSIXSPAWNSETSCHEDULER flag is set  in  spawn-flags
     attribute  of  the object referenced by attrp (regardless of
     the setting of the POSIXSPAWNSETSCHEDPARAM flag), the  new
     process  image initially has the scheduling policy specified
     in the spawn-schedpolicy attribute of the object  referenced
     by  attrp  and  the  scheduling  parameters specified in the
     spawn-schedparam attribute of the same object.




SunOS 5.11          Last change: 20 Feb 2009                    3






Standard C Library Functions                      posixspawn(3C)



     The POSIXSPAWNRESETIDS flag in the  spawn-flags  attribute
     of the object referenced by attrp governs the effective user
     ID of the child process. If this flag is not set, the  child
     process  inherits the parent process's effective user ID. If
     this flag is set, the child process's effective user  ID  is
     reset  to  the parent's real user ID. In either case, if the
     set-user-ID mode bit of the new process image file  is  set,
     the  effective  user  ID  of  the child process becomes that
     file's owner ID before the new process image  begins  execu-
     tion.  If  this  flag  is set, the child process's effective
     user ID is reset to the parent's real  user  ID.  In  either
     case,  if  the set-user-ID mode bit of the new process image
     file is set, the effective user  ID  of  the  child  process
     becomes  that  file's  owner ID before the new process image
     begins execution.


     The POSIXSPAWNRESETIDS flag in the  spawn-flags  attribute
     of the object referenced by attrp also governs the effective
     group ID of the child process. If this flag is not set,  the
     child  process inherits the parent process's effective group
     ID. If this flag is set, the child process's effective group
     ID  is  reset to the parent's real group ID. In either case,
     if the set-group-ID mode bit of the new process  image  file
     is  set, the effective group ID of the child process becomes
     that file's group ID before the  new  process  image  begins
     execution.


     If the POSIXSPAWNSETSIGMASK flag is set in the spawn-flags
     attribute  of the object referenced by attrp, the child pro-
     cess initially has the signal mask specified in  the  spawn-
     sigmask attribute of the object referenced by attrp.


     If the POSIXSPAWNSETSIGDEF flag is set in the  spawn-flags
     attribute  of  the  object  referenced by attrp, the signals
     specified in the  spawn-sigdefault  attribute  of  the  same
     object is set to their default actions in the child process.


     If the POSIXSPAWNSETSIGIGNP flag is set  in  the  spawn-
     flags  attribute of the object referenced by attrp, the sig-
     nals specified in the spawn-sigignore attribute of the  same
     object are set to be ignored in the child process.


     If both POSIXSPAWNSETSIGDEF  and  POSIXSPAWNSETSIGIGNP
     flags  are  set  in  the spawn-flags attribute of the object
     referenced by attrp, the actions  for  POSIXSPAWNSETSIGDEF
     take      precedence      over      the      actions     for
     POSIXSPAWNSETSIGIGNP.



SunOS 5.11          Last change: 20 Feb 2009                    4






Standard C Library Functions                      posixspawn(3C)



     If the POSIXSPAWNOSIGCHLDNP flag is set  in  the  spawn-
     flags  attribute  of  the  object  referenced  by  attrp, no
     SIGCHLD signal will be posted to the parent process when the
     child  process  terminates, regardless of the disposition of
     the SIGCHLD signal in the parent.  SIGCHLD signals are still
     possible  for  job  control stop and continue actions if the
     parent has requested them.


     If the POSIXSPAWNWAITPIDNP flag is set in the spawn-flags
     attribute  of  the  object referenced by attrp, no wait-for-
     multiple-pids  operation  by  the  parent,  as  in   wait(),
     waitid(PAL),  or  waitid(PGID),  will succeed in reaping
     the child, and the child will not  be  reaped  automatically
     due  the  disposition  of the SIGCHLD signal being set to be
     ignored in the parent.  Only a specific wait for the  child,
     as  in  waitid(PID,  pid),  is allowed and it is required,
     else when the child exits it will remain a zombie until  the
     parent exits.


     If the POSIXSPAWNOEXECERNP flag is set  in  the  spawn-
     flags  attribute  of  the object referenced by attrp, and if
     the specified process image file cannot  be  executed,  then
     the  posixspawn()  and posixspawnp() functions do not fail
     with one of the exec(2)  error  codes,  as  is  normal,  but
     rather  return  successfully  having created a child process
     that exits immediately with exit status 127. This flag  per-
     mits   system(3C)  and  popen(3C)  to  be  implemented  with
     posixspawn() and still  conform  strictly  to  their  POSIX
     specifications.


     Signals set to be caught or set to the default action in the
     calling  process  are set to the default action in the child
     process, unless the POSIXSPAWNSETSIGIGNP flag is set  in
     the  spawn-flags attribute of the object referenced by attrp
     and the signals are specified in the spawn-sigignore  attri-
     bute of the same object.


     Except for SIGCHLD, signals set to be ignored by the calling
     process  image  are  set to be ignored by the child process,
     unless otherwise specified by the POSIXSPAWNSETSIGDEF flag
     being  set in the spawn-flags attribute of the object refer-
     enced by attrp  and  the  signals  being  indicated  in  the
     spawn-sigdefault  attribute  of  the  object  referenced  by
     attrp.


     If the SIGCHLD signal is set to be ignored  by  the  calling
     process, it is unspecified whether the SIGCHLD signal is set



SunOS 5.11          Last change: 20 Feb 2009                    5






Standard C Library Functions                      posixspawn(3C)



     to be ignored or to the default action in the child process,
     unless otherwise specified by the POSIXSPAWNSETSIGDEF flag
     being set in the spawn-flags attribute of the object  refer-
     enced by attrp and the SIGCHLD signal being indicated in the
     spawn-sigdefault  attribute  of  the  object  referenced  by
     attrp.


     If the value of the attrp pointer is NUL, then the  default
     values are used.


     All process attributes, other than those influenced  by  the
     attributes  set  in the object referenced by attrp as speci-
     fied above or by the file descriptor manipulations specified
     in  fileactions  appear  in the new process image as though
     fork() had been called to create a child process and then  a
     member  of  the  exec family of functions had been called by
     the child process to execute the new process image.


     The  fork  handlers  are  not  run  when  posixspawn()   or
     posixspawnp() is called.

RETURN VALUES
     Upon successful completion, posixspawn() and posixspawnp()
     return  the  process  ID  of the child process to the parent
     process in the variable pointed to by a non-null  pid  argu-
     ment,  and  return zero as the function return value. Other-
     wise, no child process is created, the value stored into the
     variable pointed to by a non-null pid is unspecified, and an
     error number is returned as the  function  return  value  to
     indicate  the  error. If the pid argument is a null pointer,
     the process ID of the child is not returned to the caller.

ERORS
     The posixspawn() and posixspawnp() functions will fail if:

     EINVAL    The value specified by fileactions  or  attrp  is
               invalid.



     If posixspawn() or posixspawnp() fails for any of the rea-
     sons  that  would  cause fork() or one of the exec family of
     functions to fail, an error value is returned  as  described
     by fork(2) and exec(2), respectively


     If POSIXSPAWNSETPGROUP is set in the spawn-flags attribute
     of  the  object  referenced  by  attrp, and posixspawn() or
     posixspawnp() fails  while  changing  the  child's  process



SunOS 5.11          Last change: 20 Feb 2009                    6






Standard C Library Functions                      posixspawn(3C)



     group,   an   error   value  is  returned  as  described  by
     setpgid(2).


     If      POSIXSPAWNSETSCHEDPARAM      is      set       and
     POSIXSPAWNSETSCHEDULER  is  not  set  in  the  spawn-flags
     attribute  of  the  object  referenced  by  attrp,  then  if
     posixspawn() or posixspawnp() fails for any of the reasons
     that would cause schedsetparam() to fail, an error value is
     returned as described by schedsetparam(3C).


     If POSIXSPAWNSETSCHEDULER is set in the spawn-flags attri-
     bute of the object referenced by attrp, and if posixspawn()
     or posixspawnp() fails for any of the  reasons  that  would
     cause  schedsetscheduler()  to  fail,  an  error  value  is
     returned as described by schedsetscheduler(3C).


     If the fileactions argument is not NUL and  specifies  any
     close(),  dup2(),  or open() actions to be performed, and if
     posixspawn() or posixspawnp() fails for any of the reasons
     that  would  cause  close(),  dup2(),  or open() to fail, an
     error value is returned as described by close(2),  dup2(3C),
     or  open(2),  respectively.  An  open  file action might, by
     itself, result in any of the errors described by close()  or
     dup2(), in addition to those described by open().


     If a close(2) operation is specified to be performed  for  a
     file  descriptor that is not open at the time of the call to
     posixspawn() or posixspawnp(), the action does  not  cause
     posixspawn() or posixspawnp() to fail.

ATRIBUTES
     See attributes(5) for descriptions of the  following  attri-
     butes:


















SunOS 5.11          Last change: 20 Feb 2009                    7






Standard C Library Functions                      posixspawn(3C)



     
           ATRIBUTE TYPE               ATRIBUTE VALUE       
    
     Interface Stability          Committed                   
    
     MT-Level                     MT-Safe                     
    
     Standard                     See standards(5).           
    


SEE ALSO
     alarm(2),  chmod(2),  close(2),  dup(2),  exec(2),  exit(2),
     fcntl(2),  fork(2), kill(2), open(2), setpgid(2), setuid(2),
     stat(2),        times(2),        dup2(3C),        popen(3C),
     posixspawnfileactionsaddclose(3C),
     posixspawnfileactionsadddup2(3C),
     posixspawnfileactionsaddopen(3C),
     posixspawnfileactionsdestroy(3C),
     posixspawnfileactionsinit(3C),
     posixspawnattrdestroy(3C),   posixspawnattrgetflags(3C),
     posixspawnattrgetpgroup(3C),
     posixspawnattrgetschedparam(3C),
     posixspawnattrgetschedpolicy(3C),
     posixspawnattrgetsigdefault(3C),
     posixspawnattrgetsigignorenp(3C),
     posixspawnattrgetsigmask(3C),    posixspawnattrinit(3C),
     posixspawnattrsetflags(3C), posixspawnattrsetpgroup(3C),
     posixspawnattrsetschedparam(3C),
     posixspawnattrsetschedpolicy(3C),
     posixspawnattrsetsigdefault(3C),
     posixspawnattrsetsigignorenp(3C),
     posixspawnattrsetsigmask(3C),          schedsetparam(3C),
     schedsetscheduler(3C), system(3C), wait(3C), attributes(5),
     standards(5)

NOTES
     The SUSv3 POSIX standard (The Open Group Base Specifications
     Issue 6, IE Std 1003.1-2001) permits the posixspawn() and
     posixspawnp() functions to return successfully before  some
     of  the  above-described  errors  are detected, allowing the
     child process to fail instead:

       ... if the error occurs after the calling process
       successfully returns, the child process exits with
       exit status 127.



     With the one exception of when the  POSIXSPAWNOEXECERNP
     flag is passed in the attributes structure, this behavior is
     not present in the Solaris implementation.  Any  error  that



SunOS 5.11          Last change: 20 Feb 2009                    8






Standard C Library Functions                      posixspawn(3C)



     occurs  before  the  new  process image is successfully con-
     structed causes the posixspawn() and  posixspawnp()  func-
     tions  to  return  the  corresponding  non-zero  error value
     without creating a child process.


     The    POSIXSPAWNOSIGCHLDNP,     POSIXSPAWNWAITPIDNP,
     POSIXSPAWNOEXECERNP, and POSIXSPAWNSETSIGIGNP flags
     and      the      posixspawnattrgetsigignorenp()      and
     posixspawnattrsetsigignorenp() functions are non-portable
     Solaris extensions to the posixspawn()  and  posixspawnp()
     interfaces.











































SunOS 5.11          Last change: 20 Feb 2009                    9



OpenSolaris man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™