---
name: "posix_spawn_file_actions_init"
section: "3"
platform: "macos"
package: "xnu"
version: "12377.121.6"
release: "macOS 26.5"
platforms: ["freebsd", "macos"]
url: "https://new.carta.tech/posix_spawn_file_actions_init"
---

# posix\_spawn\_file\_actions\_init(3)

initialize or destroy spawn file actions objects

## NAME

**posix\_spawn\_file\_actions\_init** **posix\_spawn\_file\_actions\_destroy** – initialize or destroy spawn file actions objects

## SYNOPSIS

**#include \<spawn.h\>**

*int*\

**posix\_spawn\_file\_actions\_init**(*posix\_spawn\_file\_actions\_t \*file\_actions*);

*int*\

**posix\_spawn\_file\_actions\_destroy**(*posix\_spawn\_file\_actions\_t \*file\_actions*);

## DESCRIPTION

The **posix\_spawn\_file\_actions\_init**() function initializes the object referenced by *file\_actions*, to an empty set of file actions for subsequent use in a call to [posix\_spawn(2)](/posix_spawn/2.md) or  posix\_spawnp(2). A *posix\_spawn\_file\_actions\_t* object is an opaque type that is used to collect set of file actions specified by calls to [posix\_spawn\_file\_actions\_addclose(3)](/posix_spawn_file_actions_addclose/3.md) and [posix\_spawn\_file\_actions\_addopen(3)](/posix_spawn_file_actions_addopen/3.md) such that once the spawn operation is complete, the child process will have a different set of file descriptors than the parent, in the order that the operations were added to the *posix\_spawn\_file\_actions\_t*.

Additionally, any descriptor in the parent not modified by a file action, and which has the FD\_CLOEXEC flag set, will be closed in the child.

The **posix\_spawn\_file\_actions\_destroy**() function destroys the object referenced by *file\_actions* which was previously intialized by **posix\_spawn\_file\_actions\_init**(), returning any resources obtained at the time of initialization to the system for subsequent reuse.  A *posix\_spawn\_file\_actions\_t* may be reinitialized after having been destroyed, but *must* *not* be reused after destruction, unless it has been reinitialized.

## RETURN VALUES

On success, these functions return 0; on failure they return an error number from ⟨errno.h⟩.

## ERRORS

These functions will fail and return an error if:

- \[ENOMEM\]

  Insufficient resources to initialize the *posix\_spawn\_file\_actions\_t* object.

- \[EINVAL\]

  The *posix\_spawn\_file\_actions\_t* being destroyed is invalid.

## SEE ALSO

[posix\_spawn(2)](/posix_spawn/2.md), posix\_spawnp(2), [posix\_spawn\_file\_actions\_addclose(3)](/posix_spawn_file_actions_addclose/3.md), [posix\_spawn\_file\_actions\_addopen(3)](/posix_spawn_file_actions_addopen/3.md), [posix\_spawn\_file\_actions\_adddup2(3)](/posix_spawn_file_actions_adddup2/3.md)

## STANDARDS

Version 3 of the Single UNIX Specification (“SUSv3”)

## HISTORY

The **posix\_spawn\_file\_actions\_init**() and **posix\_spawn\_file\_actions\_destroy**() function calls appeared in Version 3 of the Single UNIX Specification (“SUSv3”).
