4 ms·
I caught the same thing, but learned something interesting while double checking I wasn't crazy (from man 2 fork): Since version 2.3.3, rather than invoking
by andrewvc 16y ago
I caught the same thing, but learned something interesting while double checking I wasn't crazy (from man 2 fork):
Since version 2.3.3, rather than invoking the kernel's fork() system
call, the glibc fork() wrapper that is provided as part of the NPTL threading implementation invokes clone(2) with flags that provide the same effect as the traditional system call. The glibc wrapper invokes any fork handlers that have been established using pthread_atfork(3).
At least on my ubuntu box.
andrew-think ⚑ ~ strace -f sh -c 'sh &' 2>&1 | egrep -A1 'clone|fork'
clone(Process 2646 attached
child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7ff002bac9d0) = 2646
- tedunangst 16y agoAh, but just because glibc doesn't call the fork() system call doesn't mean the kernel doesn't have one. :) I bet you could still get to by calling something like __glibc_old_fork(), or at the very least a manual syscall(SYS_FORK) should work. POSIX itself doesn't even use the words system call, only function, to describe them.
- andrewvc 16y agoYep: $ grep fork /usr/include/asm/unistd_64.h #define __NR_fork 57 __SYSCALL(__NR_fork, stub_fork) #define __NR_vfork 58 __SYSCALL(__NR_vfork, stub_vfork) $ strace -f ruby -e 'syscall 57' 2>&1 | egrep 'fork|clone' fork(Process 4138 attached (waiting for parent) $ strace -f ruby -e 'fork' 2>&1 | egrep 'fork|clone' execve("/home/andrew/.rvm/rubies/ree-1.8.7-2010.02/bin/ruby", ["ruby", "-e", "fork"], [/* 47 vars */]) = 0 clone(Process 4145 attached