I'd like to use the namespacing features of the clone
function. Reading the manpage, it seems like clone
has lots of intricate details I need to worry about.
Is there an equivalent clone
invocation to good ol' fork()
?
I'm already familiar with fork
, and believe that if I have a starting point in clone
, I can add flags and options from there.
A fork creates a completely independent copy of Git repository. In contrast to a fork, a Git clone creates a linked copy that will continue to synchronize with the target repository.
5. clone() The clone() system call is an upgraded version of the fork call. It's powerful since it creates a child process and provides more precise control over the data shared between the parent and child processes.
If you don't intend to make changes to code, clone but don't fork. Forking is intended to host the commits you make to code, while cloning is perfectly fine for copying the content and history of the project.
I think that this will work, but I'm not entirely certain about some of the pointer arguments.
pid_t child = clone( child_f, child_stack,
/* int flags */ SIGCHLD,
/* argument to child_f */ NULL,
/* pid_t *pid */ NULL,
/* struct usr_desc * tls */ NULL,
/* pid_t *ctid */ NULL );
In the flags parameter the lower byte of it is used to specify which signal to send to notify the parent of the thread doing things like dying or stopping. I believe that all of the actual flags turn on switches which are different from fork
. Looking at the kernel code suggests this is the case.
If you really want to get something close to fork
you may want to call sys_clone
which does not take function pointer and instead returns twice like fork
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With