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,2001 by Erik Andersen <andersen@uclibc.org>
7 * Written by Erik Andersen <andersen@uclibc.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
19 * You should have received a copy of the GNU Library General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "clone_cruft.h"
36 #define ALLGOT (GOT1|GOT2|GOT3)
38 void child_handler(int sig)
40 printf("I got a SIGCHLD\n");
43 int clone_main(void *arg)
45 unsigned long input = (unsigned long)arg;
46 int secs = (input / 10) * 4;
47 printf("Clone got %lu, sleeping for %i secs\n", input, secs);
54 int clone1, clone2, clone3;
55 char clone1_stack[8192], clone2_stack[8192], clone3_stack[8192];
56 int status, nostatus, result, wpid;
58 signal(SIGCHLD, child_handler);
60 if ((clone1 = do_clone(clone_main, clone1_stack, 0, (void*)11)) == -1) {
61 perror("Clone 1 failed");
64 if ((clone2 = do_clone(clone_main, clone2_stack, 0, (void*)22)) == -1) {
65 perror("Clone 2 failed");
68 if ((clone3 = do_clone(clone_main, clone3_stack, 0, (void*)33)) == -1) {
69 perror("Clone 3 failed");
74 printf("Parent: waiting for the clones to die.\n");
75 nostatus = status = 0;
77 if ((wpid = waitpid(clone1, &result, WNOHANG|__WCLONE)) == -1)
81 printf("Clone1 gave back %i\n", WEXITSTATUS(result));
84 if ((wpid = waitpid(clone2, &result, WNOHANG|__WCLONE)) == -1)
88 printf("Clone2 gave back %i\n", WEXITSTATUS(result));
91 if ((wpid = waitpid(clone3, &result, WNOHANG|__WCLONE)) == -1)
95 printf("Clone3 gave back %i\n", WEXITSTATUS(result));
98 if (status == ALLGOT || nostatus == ALLGOT)
102 if (status == ALLGOT) {
103 printf("Clones exited.\nGoodbye.\n");
106 perror("Waiting for clones failed");
113 c-file-style: "linux"