1 #define _GNU_SOURCE 2 #include <unistd.h> 3 #include <signal.h> 4 #include "syscall.h" 5 #include "pthread_impl.h" 6 __vfork(void)7hidden pid_t __vfork(void) 8 { 9 /* vfork syscall cannot be made from C code */ 10 #ifdef SYS_fork 11 return syscall(SYS_fork); 12 #else 13 return syscall(SYS_clone, SIGCHLD, 0); 14 #endif 15 } 16 vfork(void)17pid_t vfork(void) 18 { 19 pthread_t self = __pthread_self(); 20 pid_t parent_pid = self->pid; 21 self->pid = 0; 22 pid_t ret = __vfork(); 23 if (ret != 0) { 24 self->pid = parent_pid; 25 } 26 return ret; 27 } 28