#include #include #include #include #include #include extern int __clone (int (*__fn) (void *__arg), void *__child_stack, int __flags, void *__arg, ...); extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base, size_t __child_stack_size, int __flags, void *__arg, ...); static int thread (void *arg) { write (2, "thread\n", sizeof ("thread\n")); *(volatile int *) 0; return 0; } #define STACK_SIZE 1024 * 1024 #define CLONE_FLAGS CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM int main (void) { void *stack = mmap (0, STACK_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0); pid_t pid; #ifdef __ia64__ pid = __clone2 (thread, stack, STACK_SIZE - 64, CLONE_FLAGS, 0); #else pid = __clone (thread, stack + STACK_SIZE - 64, CLONE_FLAGS, 0); #endif printf ("pid = %d\n", pid); sleep (1); return 0; }