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

# posix\_spawnattr\_init(3)

initialize or destroy a spawn attributes object

## NAME

**posix\_spawnattr\_init** **posix\_spawnattr\_destroy** – initialize or destroy a spawn attributes object

## SYNOPSIS

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

*int*\

**posix\_spawnattr\_init**(*posix\_spawnattr\_t \*attr*);

*int*\

**posix\_spawnattr\_destroy**(*posix\_spawnattr\_t \*attr*);

## DESCRIPTION

The **posix\_spawnattr\_init**() function initializes the object referenced by *attr*, to an empty set of spawn attributes for subsequent use in a call to [posix\_spawn(2)](/posix_spawn/2.md) or posix\_spawnp(2).

A *posix\_spawnattr\_t* object is an opaque type that is used to collect set of spawn attributes specified by calls to [posix\_spawnattr\_setflags(3)](/posix_spawnattr_setflags/3.md), [posix\_spawnattr\_setpgroup(3)](/posix_spawnattr_setpgroup/3.md), [posix\_spawnattr\_setsigdefault(3)](/posix_spawnattr_setsigdefault/3.md), [posix\_spawnattr\_setsigmask(3)](/posix_spawnattr_setsigmask/3.md), [posix\_spawnattr\_setarchpref\_np(3)](/posix_spawnattr_setarchpref_np/3.md), [posix\_spawnattr\_setbinpref\_np(3)](/posix_spawnattr_setbinpref_np/3.md), [posix\_spawnattr\_setspecialport\_np(3)](/posix_spawnattr_setspecialport_np/3.md), or posix\_spawnattr\_setexceptionports\_np(3) such that once the spawn operation is complete, the child process will have a different set of attributes than the parent.  The order of these operations is unspecified and may change; programs should not depend on their ordering.

The **posix\_spawnattr\_destroy**() function destroys the object referenced by *attr* which was previously intialized by **posix\_spawnattr\_init**(), returning any resources obtained at the time of initialization to the system for subsequent reuse.  A *posix\_spawnattr\_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

The **posix\_spawnattr\_init**() and **posix\_spawnattr\_destroy**() functions will fail and return an error if:

- \[ENOMEM\]

  Insufficient resources to initialize the *posix\_spawnattr\_t* object.

- \[EINVAL\]

  The  *posix\_spawnattr\_t* being destroyed is invalid.

## SEE ALSO

[posix\_spawn(2)](/posix_spawn/2.md), posix\_spawnp(2), [posix\_spawnattr\_setflags(3)](/posix_spawnattr_setflags/3.md), [posix\_spawnattr\_setpgroup(3)](/posix_spawnattr_setpgroup/3.md), [posix\_spawnattr\_setsigdefault(3)](/posix_spawnattr_setsigdefault/3.md), [posix\_spawnattr\_setsigmask(3)](/posix_spawnattr_setsigmask/3.md), [posix\_spawnattr\_setbinpref\_np(3)](/posix_spawnattr_setbinpref_np/3.md), [posix\_spawnattr\_setspecialport\_np(3)](/posix_spawnattr_setspecialport_np/3.md), posix\_spawnattr\_setexceptionports\_np(3)

## STANDARDS

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

## HISTORY

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