nsprpub/pr/tests/sproc_ch.c

changeset 2
7e26c7da4463
equal deleted inserted replaced
-1:000000000000 0:0e48d01201a6
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_ch.c
8 *
9 * The purpose of this test and the sproc_p.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 * There are three sprocs in this test: the parent, the child, and the
13 * grandchild. The parent and child sprocs never stop on their own.
14 * The grandchild sproc gets a segmentation fault and dies. You should
15 * You should use "ps" to see if the parent and child sprocs are killed
16 * after the grandchild dies.
17 */
18
19 #include "prinit.h"
20 #include <stdio.h>
21
22 #if !defined(IRIX)
23
24 int main(int argc, char **argv)
25 {
26 printf("This test applies to IRIX only.\n");
27 return 0;
28 }
29
30 #else /* IRIX */
31
32 #include "prthread.h"
33 #include <sys/types.h>
34 #include <unistd.h>
35
36 void SegFault(void *unused)
37 {
38 int *p = 0;
39
40 printf("The grandchild sproc has pid %d.\n", getpid());
41 printf("The grandchild sproc will get a segmentation fault and die.\n");
42 printf("The parent and child sprocs should be killed after the "
43 "grandchild sproc dies.\n");
44 printf("Use 'ps' to make sure this is so.\n");
45 fflush(stdout);
46 /* Force a segmentation fault */
47 *p = 0;
48 }
49
50 void NeverStops(void *unused)
51 {
52 int i = 0;
53
54 printf("The child sproc has pid %d.\n", getpid());
55 printf("The child sproc won't stop on its own.\n");
56 fflush(stdout);
57
58 /* create the grandchild sproc */
59 PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
60 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
61
62 while (1) {
63 i++;
64 }
65 }
66
67 int main()
68 {
69 int i= 0;
70
71 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
72
73 printf("The parent sproc has pid %d.\n", getpid());
74 printf("The parent sproc won't stop on its own.\n");
75 fflush(stdout);
76
77 /* create the child sproc */
78 PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
79 PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
80
81 while (1) {
82 i++;
83 }
84 return 0;
85 }
86
87 #endif /* IRIX */

mercurial