RFORK_THREAD(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ¦‹ NAME πŸ¦‹

okay so hi bestie, this is RFORK_THREAD(3) from the Library Functions Manual, and it's giving: rfork_thread β€” create a rfork-based process thread. that's the name and the function, we're already slaying πŸ’…

πŸŽ€ LIBRARY πŸŽ€

Standard C Library (libc, -lc) β€” that's where this lives, periodt.

✨ SYNOPSIS ✨

#include <unistd.h>

pid_t
rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg);

πŸ’– DESCRIPTION πŸ’–

⚠️ deprecated alert, bestie: rfork_thread() has been deprecated in favor of pthread_create(3). so it's still here and still documented, but it is not the main character anymore πŸ’€

so what does it do? it's a helper function for rfork(2). it arranges for a new process to be created, and the child process will call the specified function with the specified argument, while running on the supplied stack. that's the whole setup, iykyk.

using this function should avoid the need to implement complex stack swap code. that's the tea β˜•

🌸 RETURN VALUES 🌸

upon successful completion, rfork_thread() returns the process ID of the child process to the parent process. otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to indicate the error. no cap.

the child process context is not aware of a return from the rfork_thread() function as it begins executing directly with the supplied function. so yeah, the child starts running the function you handed it, and it doesn't come back through the normal return path 🫢

πŸ”₯ ERRORS πŸ”₯

See rfork(2) for error return codes. that's the whole section, go check that page for the error tea.

🌈 SEE ALSO 🌈

πŸ‘‘ HISTORY πŸ‘‘

the rfork_thread() function first appeared in FreeBSD 4.3. vintage behavior, honestly.


πŸ’– cute sign-off: this page is from the Debian source/version, dated February 6, 2011. bye bestie, go be iconic with your processes πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from