Re: What is the equivalent of the linux system call clone() on FreeBSD?

From: David Chisnall <theraven_at_FreeBSD.org>
Date: Sat, 08 Jul 2023 16:09:32 UTC
On 7 Jul 2023, at 22:53, Brooks Davis <brooks@freebsd.org> wrote:
> 
> clone is at least partially implemented in terms of rfork(2) flags.
> It's not immediately obvious what the code is doing so I can't comment
> if you'll be able to do what you need rfork if if you really need a
> clone implementation.

The Linux kernel doesn’t really have a notion of threads as distinct from processes.  This leads to some really annoying things (the Linux equivalent of PROC_PDEATHSIG_CTL kills the child process when the parent thread exits, even if it is not the main thread in the parent process and the parent is still happily running).  This means that clone (/ clone3) is not just standing in for rfork, it is also standing in for thr_new.

Depending on exactly what you’re doing with clone, you may want one of:

 - rfork
 - pdfork
 - thr_new

Unfortunately, rfork does not have a pdfork-like variant (yet) and so there are some combinations of rfork flags that don’t let you use process descriptors (procfds in Linux), whereas in Linux these are orthogonal.

David