1 | #include <image.h>
|
---|
2 | #include <OS.h>
|
---|
3 | #include <stdio.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #include <string.h>
|
---|
6 | #include <unistd.h>
|
---|
7 |
|
---|
8 | int main (int argc, const char *argv[])
|
---|
9 | {
|
---|
10 | if (argc != 2)
|
---|
11 | {
|
---|
12 | printf ("Usage: %s 0|1\n"
|
---|
13 | "Use 0 to test with system running /bin/date,\n"
|
---|
14 | "Use 1 to test with load_image() running /bin/date.\n"
|
---|
15 | "Redirect output to a file for faster performance.\n",
|
---|
16 | argv[0]);
|
---|
17 | return 0;
|
---|
18 | }
|
---|
19 | int UseLoadImage = atoi (argv[1]);
|
---|
20 | fprintf (stderr, "Using %s to run /bin/date repeatedly, will it fail?\n",
|
---|
21 | UseLoadImage ? "load_image()" : "system()" );
|
---|
22 |
|
---|
23 | for (int i = 0; i < 1000000 ; i++)
|
---|
24 | {
|
---|
25 | fprintf (stderr, "%d ", i);
|
---|
26 | if (UseLoadImage)
|
---|
27 | {
|
---|
28 | const char *Arguments[2];
|
---|
29 | Arguments[0] = "/bin/date";
|
---|
30 | Arguments[1] = NULL;
|
---|
31 |
|
---|
32 | thread_id NewProgramID =
|
---|
33 | load_image (1 /* ArgumentCount */, Arguments,
|
---|
34 | const_cast<const char **>(environ));
|
---|
35 |
|
---|
36 | resume_thread (NewProgramID);
|
---|
37 | status_t ExitCode = -1;
|
---|
38 | wait_for_thread (NewProgramID, &ExitCode);
|
---|
39 | }
|
---|
40 | else
|
---|
41 | system ("/bin/date");
|
---|
42 |
|
---|
43 | snooze (1000);
|
---|
44 | }
|
---|
45 | printf ("Finished!\n");
|
---|
46 | fprintf (stderr, "Finished!\n");
|
---|
47 | return 0;
|
---|
48 | }
|
---|