POSIX_SPAWNATTR_SETEXECFD_NP(3)

πŸ“¦ version 15.1, in freebsd 15.1

πŸ’… posix_spawnattr_getexecfd_np(3) β€” the spawn-execfd attribute, bestie edition

okay so this one lives in the Library Functions Manual, section 3, and it's a real one β€” posix_spawnattr_getexecfd_np and posix_spawnattr_setexecfd_np, a little getter/setter duo for the spawn-execfd attribute on a spawn attributes object. πŸŽ€


🌸 NAME

posix_spawnattr_getexecfd_np, posix_spawnattr_setexecfd_np β€” get and set the spawn-execfd attribute of a spawn attributes object πŸ’…

πŸ“š LIBRARY

Standard C Library (libc, -lc) β€” she's built in, no extra shopping required ✨

πŸ¦‹ SYNOPSIS

#include <spawn.h>

int
posix_spawnattr_getexecfd_np(const posix_spawnattr_t *restrict attr,
    int *restrict fdp);

int
posix_spawnattr_setexecfd_np(posix_spawnattr_t *attr, int fd);

πŸ”₯ DESCRIPTION

okay so picture this: posix_spawnattr_getexecfd_np() reaches into the attributes object that attr points at and obtains the value of the spawn-execfd attribute. she's just reading the vibe check result, no cap 🫢

then posix_spawnattr_setexecfd_np() does the opposite β€” it sets the spawn-execfd attribute on an initialized attributes object referenced by attr. main character energy, she's the one writing πŸ’…

so what IS this attribute, you ask? good question bestie. the spawn-execfd attribute hands over the file descriptor that the posix_spawn(3) family of functions uses to execute the new image in the spawned process. iconic behavior ✨

here's the important part, don't skip it πŸ™ˆ β€” if the attribute is set to a value other than -1, it must be a valid file descriptor which does not have the O_CLOFORK flag set. then posix_spawn() executes the executable image referenced by the file descriptor in the newly created process, using the fexecve(2) system call. and in that case? the path argument to posix_spawn() is ignored. literally thrown away, not even a look πŸ‘‘πŸ˜­

the default value for the spawn-execfd attribute is -1, which means the executed image is specified by the path argument to posix_spawn(). so that's the "business as usual" setting 🌈

⭐ real talk: non--1 means the fd has to be legit and must not carry O_CLOFORK. don't play with that one πŸ’€

πŸŽ€ RETURN VALUES

posix_spawnattr_getexecfd_np() and posix_spawnattr_setexecfd_np() both return zero. that's it. zero. slay, no drama, no mysterious negative numbers to debug at 3am πŸ’–

πŸ‘‘ SEE ALSO

the whole friend group, go say hi πŸ¦‹

πŸ’€ STANDARDS

posix_spawnattr_getexecfd_np() and posix_spawnattr_setexecfd_np() are FreeBSD extensions that first appeared in FreeBSD 16.0. so she's not POSIX, she's not portable, she's FreeBSD's girlie 🌸


and that's the page, bestie! 🫢 this one came from Debian, dated January 25, 2026, and the footer signs off as POSIX_SPAWNATTR_GETEXECFD_NP(3) β€” mwah, go read the source next, iykyk πŸ’œβœ¨

πŸ“¦ where this page comes from