2 * Simple user-land program instead of real "init"
9 #include <asm/ioctls.h>
12 #include <linux/reboot.h>
15 static volatile unsigned long long counter
;
18 main_test_speed(unsigned sec
, unsigned n
)
24 printf("Testing speed with %d threads\n", n
);
29 for(i
= 0; i
< n
; i
++ )
32 if( (pid
= fork()) != 0 )
36 while( time(NULL
) < (start
+ sec
) )
38 printf("Counter %llu\n", counter
);
39 write( pfd
[1], (void *) &counter
, sizeof(counter
) );
42 /* Children running, parent waits */
44 while( time(NULL
) < (start
+ sec
) )
47 /* Retreive child exist status */
48 for(counter
= i
= 0; i
< n
; i
++ )
50 unsigned long long cnt
;
52 if( read(pfd
[0], &cnt
, sizeof(cnt
)) == sizeof(cnt
))
55 printf("child %d status %d\n", i
, WEXITSTATUS(res
));
57 printf("Average count %llu, or %d per sec \n",
58 counter
/ n
, (int) (counter
/ n
/ sec
) );
63 main(int argc
, char ** argv
)
66 const unsigned seconds
= 60;
67 const unsigned dt
= 5;
70 printf("Howdy from user-land! ! ! !\n");
72 for(j
= i
= 0; i
< seconds
; i
+= dt
)
75 printf("Time is %d sec\n", time(NULL
) );
76 ioctl(0, FIONREAD
, &j
);
79 memset(buf
, 0, sizeof(buf
));
80 j
= read(0, buf
, sizeof(buf
));
81 printf("Received %d characters from input:\n", j
);
82 printf("'%s'\n", buf
);
87 main_test_speed( 30, 1 );
89 main_test_speed( 30, 2 );
91 main_test_speed( 30, 3 );
93 main_test_speed( 30, 4 );
95 ioctl(0, FIONREAD
, &j
);
98 memset(buf
, 0, sizeof(buf
));
99 j
= read(0, buf
, sizeof(buf
));
100 printf("Received %d characters from input:\n", j
);
101 printf("'%s'\n", buf
);
104 printf("Done couning, commiting suicide...\n");
106 reboot( LINUX_REBOOT_CMD_RESTART
);
108 printf("reboot failed: %s\n", strerror(errno
) );