1 /* vi: set sw=4 ts=4: */
3 * clone test for uClibc
4 * Copyright (C) 2000-2006 by Erik Andersen <andersen@uclibc.org>
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
15 #include "clone_cruft.h"
20 #define ALLGOT (GOT1|GOT2|GOT3)
22 static void child_handler(int sig
)
24 printf("I got a SIGCHLD\n");
27 static int clone_main(void *arg
)
29 unsigned long input
= (unsigned long)arg
;
30 int secs
= (input
/ 10) * 4;
31 printf("Clone got %lu, sleeping for %i secs\n", input
, secs
);
38 int clone1
, clone2
, clone3
;
39 char clone1_stack
[8192], clone2_stack
[8192], clone3_stack
[8192];
40 int status
, nostatus
, result
, wpid
;
42 signal(SIGCHLD
, child_handler
);
44 if ((clone1
= do_clone(clone_main
, clone1_stack
, 0, (void*)11)) == -1) {
45 perror("Clone 1 failed");
48 if ((clone2
= do_clone(clone_main
, clone2_stack
, 0, (void*)22)) == -1) {
49 perror("Clone 2 failed");
52 if ((clone3
= do_clone(clone_main
, clone3_stack
, 0, (void*)33)) == -1) {
53 perror("Clone 3 failed");
58 printf("Parent: waiting for the clones to die.\n");
59 nostatus
= status
= 0;
61 if ((wpid
= waitpid(clone1
, &result
, WNOHANG
|__WCLONE
)) == -1)
65 printf("Clone1 gave back %i\n", WEXITSTATUS(result
));
68 if ((wpid
= waitpid(clone2
, &result
, WNOHANG
|__WCLONE
)) == -1)
72 printf("Clone2 gave back %i\n", WEXITSTATUS(result
));
75 if ((wpid
= waitpid(clone3
, &result
, WNOHANG
|__WCLONE
)) == -1)
79 printf("Clone3 gave back %i\n", WEXITSTATUS(result
));
82 if (status
== ALLGOT
|| nostatus
== ALLGOT
)
86 if (status
== ALLGOT
) {
87 printf("Clones exited.\nGoodbye.\n");
90 perror("Waiting for clones failed");