3 #output: got: a\nthen: bc\nexit: 0\n
6 /* This is a very limited subset of what ex1.c does; we just check that
7 thread creation (clone syscall) and pipe writes and reads work. */
15 #include <sys/types.h>
24 if (write (pip
[1], s
+2, 1) != 1) abort ();
25 if (write (pip
[1], s
+1, 1) != 1) abort ();
26 if (write (pip
[1], s
, 1) != 1) abort ();
43 fprintf (stderr
, "Bad pipe %d\n", retcode
);
47 pid
= clone (process
, (char *) stack
+ sizeof (stack
) - 64,
48 (CLONE_VM
| CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
)
52 fprintf (stderr
, "Bad clone %d\n", pid
);
56 if ((retcode
= read (pip
[0], buf
, 1)) != 1)
58 fprintf (stderr
, "Bad read 1: %d\n", retcode
);
61 printf ("got: %c\n", buf
[0]);
62 retcode
= read (pip
[0], buf
, 2);
65 retcode
= read (pip
[0], buf
+1, 1);
68 fprintf (stderr
, "Bad read 1.5: %d\n", retcode
);
75 fprintf (stderr
, "Bad read 2: %d\n", retcode
);
79 printf ("then: %s\n", buf
);
80 retcode
= wait4 (-1, &st
, WNOHANG
| __WCLONE
, NULL
);
82 if (retcode
!= pid
|| !WIFEXITED (st
))
84 fprintf (stderr
, "Bad wait %d %x\n", retcode
, st
);
88 printf ("exit: %d\n", WEXITSTATUS (st
));