Linux glibc clone(2) vs fork(2)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Linux glibc clone(2) vs fork(2)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Linux glibc clone(2) vs fork(2)  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:20 PM

What is the glibc clone(2) equivalent of fork(2)? The prototype is:

#include <sched.h>

int clone(int (*fn)(void *), void *child_stack, int flags, void *arg);

If I simply replace:

if (fork() == 0) {
fn(fn_arg);
exit(0);
}

with:

clone(fn, malloc(0xFFFF), SIGCHLD, fn_arg);

I do not get the same behavior. I'm in the process of tracking down
exactly what *is* different now but I'd really appreciate it if someone
would clue me in.

Thanks,
Mike





[ Post a follow-up to this message ]



    Re: Linux glibc clone(2) vs fork(2)  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:20 PM

Michael B Allen <mba2000@ioplex.com> writes:
quote:
> What is the glibc clone(2) equivalent of fork(2)?
There isn't one.
quote:
> clone(fn, malloc(0xFFFF), SIGCHLD, fn_arg); > I do not get the same behavior.
Nor should you. For one thing, stack on Linux grows in *the other* direction . Now, if you really really want to do the above (WARNING: there is really no sane justification for doing this), try: clone(fn, (char *)malloc(0x10000) + 0xFFFC, CLONE_FILES | CLONE_SIGHAND, fn_ arg); Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email.




[ Post a follow-up to this message ]



    Re: Linux glibc clone(2) vs fork(2)  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:20 PM

On Mon, 22 Dec 2003 19:34:13 -0500, Paul Pluzhnikov wrote:
quote:
> Michael B Allen <mba2000@ioplex.com> writes: > > > There isn't one. > > > Nor should you. For one thing, stack on Linux grows in *the other* > direction. > > Now, if you really really want to do the above (WARNING: there is really > no sane justification for doing this), try: > > clone(fn, (char *)malloc(0x10000) + 0xFFFC, CLONE_FILES | > CLONE_SIGHAND, fn_arg);
That worked. Thanks. Yes, I know this is not supposed to be used directly but I'm at a point in my server implementation where I can see everything I've coded so far work if I can just share the file table. With this little change indeed it all works. Flawlessly to my surprise! I've taken my measurements (22% drop in performance over threads). Now I need to implement descriptor passing ... I'm curious though; will this support changing security contexts or locales and so on? I'm creating a "multiple processes accessing all data in shared memory coordiated with System V semaphores" model. Eventually I want to be able to service clients with worker procs that can setuid, setlocale, etc based on handler requirements. Is this do-able with this CLONE_FILES thing or is it no better than threads in this respect? Do you know of other operating systems that support sharing the file descriptor table? If descriptor passing turns out to be a big drop in performance it might be worth it to be able to take advantage of this feature if the system supports it. It also introduces some interesting security possibilities like getting the stacks from non-PROT_EXEC mmap'd memory. Mike




[ Post a follow-up to this message ]



    Re: Linux glibc clone(2) vs fork(2)  
Michael B Allen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:20 PM

On Tue, 23 Dec 2003 02:54:35 -0500, Michael B Allen wrote:
quote:
> it all works. Flawlessly to my surprise! I've taken my measurements (22% > drop in performance over threads).
Mmm, no. It's actually an 11% *increase* in performance with processes vs threads. Wierd. Mike




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:29 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register