exec() without forking using posix_spawn()

A UNIX® program may exec without forking. The result is that the calling process executes another binary, but inherits certain properties, for example, file descriptors.

The P.I.P.S. equivalent would be to call posix_spawn() and pass any inherited data via argv parameters.

Note that if a parent process is waiting for the child to terminate then the termination of the newly created task must be synchronised. Therefore a waitpid() call should follow the posix_spawn() call so that it does not exit prematurely. Otherwise exit() can be called after the posix_spawn().

Also, note that if the process which formerly executed and which now uses posix_spawn() stores its PID (for example, in the file system) to allow other processes to target it, then care must be taken to store the relevant PID (Process ID). This is because the PID for the newly spawned process may need to be stored instead.