11 int thread1_func(void *arg)
17 snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg);
18 write(1, buf, strlen(buf));
24 int thread2_func(void *arg)
29 snprintf(buf, sizeof(buf), "thread2: %d %s\n", i, (char *)arg);
30 write(1, buf, strlen(buf));
36 #define STACK_SIZE 16384
40 uint8_t *stack1, *stack2;
41 int pid1, pid2, status1, status2;
43 stack1 = malloc(STACK_SIZE);
44 pid1 = clone(thread1_func, stack1 + STACK_SIZE,
45 CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, "hello1");
47 stack2 = malloc(STACK_SIZE);
48 pid2 = clone(thread2_func, stack2 + STACK_SIZE,
49 CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, "hello2");
51 while (waitpid(pid1, &status1, 0) != pid1);
52 while (waitpid(pid2, &status2, 0) != pid2);
53 printf("status1=0x%x\n", status1);
54 printf("status2=0x%x\n", status2);
55 printf("End of clone test.\n");
58 int main(int argc, char **argv)