Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.c « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a7c61665aad1f604e50bb1dbadc9a34c0a8bcdd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* test.c: misc Cygwin testing code

   Copyright 1996, 1998, 1999, 2000, 2001 Red Hat, Inc.

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#include <stdio.h>
#include <windows.h>

char a[] ="This is static data";

void
test1()
{
  int depth = 0;
  while (depth < 5) 
    {
      int  r;
      printf ("about to fork %d\n", depth);

      r = fork ();

      if (r == 0)
	{
	  int res;
	  depth++;
	  printf ("************Depth is %d\n", depth);
	  sleep (1);
	}
      else 
	{
	  printf ("This is the parent, quitting %d\n", depth);
	  sleep (1);
	  exit (1);
	}
      printf ("done loop, depth %d\n", depth);
    }
}

#define N 10
int v[N];
startup ()
{
  int i;
  for (i = 0; i < N; i++)
    {
      int r;
      fflush (stdout);
      r = fork ();
      if (r) 
	{
	  v[i] = r;
	  printf ("started %d, were'id %d\n", v[i], GetCurrentProcessId ());
	  fflush (stdout);
	}
      else
	{
	  /* running the child, sleep a bit and exit. */
	  printf ("the fork said 0, were %d\n", GetCurrentProcessId ());
	  fflush (stdout);
  sleep (2);
	  printf ("Running, and exiting %d\n", i);
	  fflush (stdout);
	  _exit (i + 0x30);
	}
    }
}

test2()
{
  int i;
  startup ();
  sleep (1);
  /* Wait for them one by one */
  for (i = 0; i < N; i++) 
    {
      int res;
      
      waitpid (v[i], &res, 0);
      printf ("Process %d gave res %x\n", v[i], res);
      if (res != (0x30 + i) << 8)
	printf ("***** BAD *** Process %d gave res %x\n", v[i], res);
    }
}

test3()
{
  int i;
  startup ();
  /* Wait for them all at the same time */
  for (i = 0; i < N; i++) 
    {
      int res;
      wait (&res);
      printf ("Got res %x\n", res);
    }
}

test5()
{
  char *c = strdup ("HI STEVE");
  printf ("c is %s\n", c);
  free (c);
}

int count;

main (int ac, char **av)
{
  int r;
  int done;
  int test;
  fprintf (stderr,"TO STDERR\n");
  if (ac < 2) {
		printf ("usage: test <n>\n");
		exit (2);
	      }
  test = atoi (av[1]);

  printf ("%d %d Hi steve, about to start fork test %d %d.\n",getpid (), count++, test,
	 GetCurrentProcessId ());
fflush (stdout);
  switch (test) 
    {
    case 1:
      test1();
      break;
    case 2:
      test2();
      break;
    case 3:
      test3();
      break;
    case 4:
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);
break;
    case 5:
      test5();
break;
    }

}

free ()
{
  printf ("MY FREE!\n");
}

char b[100000];
int i;

malloc (x)
{
char *r = b + i;
i += x;
return r;
}

realloc ()
{
}