|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Test sproc_p.c |
|
8 * |
|
9 * The purpose of this test and the sproc_ch.c test is to test the shutdown |
|
10 * of all the IRIX sprocs in a program when one of them dies due to an error. |
|
11 * |
|
12 * In this test, the parent sproc gets a segmentation fault and dies. |
|
13 * The child sproc never stops on its own. You should use "ps" to see if |
|
14 * the child sproc is killed after the parent dies. |
|
15 */ |
|
16 |
|
17 #include "prinit.h" |
|
18 #include <stdio.h> |
|
19 |
|
20 #if !defined(IRIX) |
|
21 |
|
22 int main(int argc, char **argv) |
|
23 { |
|
24 printf("This test applies to IRIX only.\n"); |
|
25 return 0; |
|
26 } |
|
27 |
|
28 #else /* IRIX */ |
|
29 |
|
30 #include "prthread.h" |
|
31 #include <sys/types.h> |
|
32 #include <unistd.h> |
|
33 |
|
34 void NeverStops(void *unused) |
|
35 { |
|
36 int i = 0; |
|
37 |
|
38 printf("The child sproc has pid %d.\n", getpid()); |
|
39 printf("The child sproc won't stop on its own.\n"); |
|
40 fflush(stdout); |
|
41 |
|
42 /* I never stop */ |
|
43 while (1) { |
|
44 i++; |
|
45 } |
|
46 } |
|
47 |
|
48 int main() |
|
49 { |
|
50 int *p = 0; |
|
51 |
|
52 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
|
53 |
|
54 printf("The parent sproc has pid %d.\n", getpid()); |
|
55 printf("The parent sproc will first create a child sproc.\n"); |
|
56 printf("Then the parent sproc will get a segmentation fault and die.\n"); |
|
57 printf("The child sproc should be killed after the parent sproc dies.\n"); |
|
58 printf("Use 'ps' to make sure this is so.\n"); |
|
59 fflush(stdout); |
|
60 |
|
61 PR_CreateThread(PR_USER_THREAD, NeverStops, NULL, |
|
62 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); |
|
63 |
|
64 /* Force a segmentation fault */ |
|
65 *p = 0; |
|
66 return 0; |
|
67 } |
|
68 |
|
69 #endif /* IRIX */ |