test structure too
[tridge/junkcode.git] / rand_syscall.c
1 #include <sys/types.h>
2 #include <sys/wait.h>
3 #include <stdio.h>
4 #include <signal.h>
5 #include <unistd.h>
6 #include <syscall.h>
7
8
9 static void rand_syscalls(void)
10 {
11         int a[7];
12         int i;
13
14         signal(SIGTERM, exit);
15
16         srandom(getpid() ^ time(NULL));
17
18         while (1) {
19                 for (i=0;i<7;i++) a[i] = random();
20                 syscall(a[0] % 1000, a[1], a[2], a[3], a[4], a[5], a[6]);
21         }
22 }
23
24 static void launch(void)
25 {
26         waitpid(-1, NULL, WNOHANG);
27         if (fork() == 0) rand_syscalls();
28 }
29
30 int main(int argc, char *argv[])
31 {
32         int nproc=1;
33         int i, status;
34
35         if (argc > 1) {
36                 nproc = atoi(argv[1]);
37         }
38
39         signal(SIGTERM, SIG_IGN);
40         signal(SIGCHLD, launch);
41
42         for (i=0;i<nproc;i++) {
43                 launch();
44         }
45
46         while (1) {
47                 kill(SIGTERM, -getpgrp());
48                 sleep(1);
49         }
50 }