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

# posix\_spawnattr\_setflags(3)

get or set flags on a posix\_spawnattr\_t

## NAME

**posix\_spawnattr\_setflags** **posix\_spawnattr\_getflags** – get or set flags on a *posix\_spawnattr\_t*

## SYNOPSIS

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

*int*\

**posix\_spawnattr\_setflags**(*posix\_spawnattr\_t \*attr*, *short flags*);

*int*\

**posix\_spawnattr\_getflags**(*const posix\_spawnattr\_t \*restrict attr*, *short \*restrict flags*);

## DESCRIPTION

The **posix\_spawnattr\_setflags**() function sets the *flags* on the attributes object referenced by *attr*.

The **posix\_spawnattr\_getflags**() function retrieves the *flags* on the attributes object referenced by *attr*.

The argument *flags* is either 0 or a bitwise OR of one or more of the following flags:

- POSIX\_SPAWN\_RESETIDS

  If this bit is set, the child process will inherit the real (rather than the effective) user and group ID of the parent process. NOTE: This flag has no effect when the set-group bit is set on the process image being spawned.

- POSIX\_SPAWN\_SETPGROUP

  If this bit is not set, then the child process inherits the parent process group; if it is set, then the child process will behave as if the [setpgid(2)](/setpgid/2.md) function had been called with a *pid* parameter of 0 and a *pgid* parameter equal to the value of the spawn-pgroup value of the *posix\_spawnattr\_t*, as set by [posix\_spawnattr\_setpgroup(3)](/posix_spawnattr_setpgroup/3.md)

- POSIX\_SPAWN\_SETSIGDEF

  Signals set to either be caught or to the default action in the parent process will also be set to the default action in the child process.  Signals set to be ignored in the parent process will be ignored in the child.  However, if this bit is set, then signals in the *spawn-sigdefault* value of the *posix\_spawnattr\_t*, as set by [posix\_spawnattr\_setsigdefault(3)](/posix_spawnattr_setsigdefault/3.md) which are caught or ignored in the parent will instead be reset to their default actions in the child.

- POSIX\_SPAWN\_SETSIGMASK

  If this bit is set, then the initial signal mask of the child process will be set to the *spawn-sigmask* value of the *posix\_spawnattr\_t*, as set by [posix\_spawnattr\_setsigmask(3)](/posix_spawnattr_setsigmask/3.md).

- POSIX\_SPAWN\_SETEXEC

  *Apple* *Extension*: If this bit is set, rather than returning to the caller, [posix\_spawn(2)](/posix_spawn/2.md) and posix\_spawnp(2) will behave as a more featureful [execve(2)](/execve/2.md).

- POSIX\_SPAWN\_START\_SUSPENDED

  *Apple* *Extension*: If this bit is set, then the child process will be created as if it immediately received a SIGSTOP signal, permitting debuggers, profilers, and other programs to manipulate the process before it begins execution in user space.  This permits, for example, obtaining exact instruction counts, or debugging very early in dyld(1). To resume the child process, it must be sent a SIGCONT signal.

- POSIX\_SPAWN\_CLOEXEC\_DEFAULT

  *Apple* *Extension*: If this bit is set, then only file descriptors explicitly created by the *file\_actions* argument are available in the spawned process; all of the other file descriptors are automatically closed in the spawned process.

## RETURN VALUES

On success, these functions return 0; on failure they return an error number from ⟨errno.h⟩. The **posix\_spawnattr\_getflags**() function additionally, upon successful completion, makes the value pointed to by the *flags* argument equal to the *spawn-flags* attribute of the *posix\_spawnattr\_t*.

## ERRORS

These functions may fail if:

- \[EINVAL\]

  The value specified by *attr* is invalid.

- \[EINVAL\]

  The value of *attr* is invalid.

## SEE ALSO

[posix\_spawn(2)](/posix_spawn/2.md), posix\_spawnp(2), [posix\_spawnattr\_init(3)](/posix_spawnattr_init/3.md), [posix\_spawnattr\_destroy(3)](/posix_spawnattr_destroy/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\_spawn\_file\_actions\_init(3)](/posix_spawn_file_actions_init/3.md), [setpgid(2)](/setpgid/2.md), [signal(3)](/signal/3.md), [execve(2)](/execve/2.md), dyld(1)

## STANDARDS

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

## HISTORY

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