1 /* vi: set sw=4 ts=4: */
3 * clone test for uClibc
5 * Copyright (C) 2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
7 * Written by Erik Andersen <andersen@uclibc.org>
9 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
18 #include "clone_cruft.h"
23 #define ALLGOT (GOT1|GOT2|GOT3)
25 void child_handler(int sig)
27 printf("I got a SIGCHLD\n");
30 int clone_main(void *arg)
32 unsigned long input = (unsigned long)arg;
33 int secs = (input / 10) * 4;
34 printf("Clone got %lu, sleeping for %i secs\n", input, secs);
41 int clone1, clone2, clone3;
42 char clone1_stack[8192], clone2_stack[8192], clone3_stack[8192];
43 int status, nostatus, result, wpid;
45 signal(SIGCHLD, child_handler);
47 if ((clone1 = do_clone(clone_main, clone1_stack, 0, (void*)11)) == -1) {
48 perror("Clone 1 failed");
51 if ((clone2 = do_clone(clone_main, clone2_stack, 0, (void*)22)) == -1) {
52 perror("Clone 2 failed");
55 if ((clone3 = do_clone(clone_main, clone3_stack, 0, (void*)33)) == -1) {
56 perror("Clone 3 failed");
61 printf("Parent: waiting for the clones to die.\n");
62 nostatus = status = 0;
64 if ((wpid = waitpid(clone1, &result, WNOHANG|__WCLONE)) == -1)
68 printf("Clone1 gave back %i\n", WEXITSTATUS(result));
71 if ((wpid = waitpid(clone2, &result, WNOHANG|__WCLONE)) == -1)
75 printf("Clone2 gave back %i\n", WEXITSTATUS(result));
78 if ((wpid = waitpid(clone3, &result, WNOHANG|__WCLONE)) == -1)
82 printf("Clone3 gave back %i\n", WEXITSTATUS(result));
85 if (status == ALLGOT || nostatus == ALLGOT)
89 if (status == ALLGOT) {
90 printf("Clones exited.\nGoodbye.\n");
93 perror("Waiting for clones failed");
100 c-file-style: "linux"