1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Test sproc_ch.c
|
---|
40 | *
|
---|
41 | * The purpose of this test and the sproc_p.c test is to test the shutdown
|
---|
42 | * of all the IRIX sprocs in a program when one of them dies due to an error.
|
---|
43 | *
|
---|
44 | * There are three sprocs in this test: the parent, the child, and the
|
---|
45 | * grandchild. The parent and child sprocs never stop on their own.
|
---|
46 | * The grandchild sproc gets a segmentation fault and dies. You should
|
---|
47 | * You should use "ps" to see if the parent and child sprocs are killed
|
---|
48 | * after the grandchild dies.
|
---|
49 | */
|
---|
50 |
|
---|
51 | #include "prinit.h"
|
---|
52 | #include <stdio.h>
|
---|
53 |
|
---|
54 | #if !defined(IRIX)
|
---|
55 |
|
---|
56 | int main()
|
---|
57 | {
|
---|
58 | printf("This test applies to IRIX only.\n");
|
---|
59 | return 0;
|
---|
60 | }
|
---|
61 |
|
---|
62 | #else /* IRIX */
|
---|
63 |
|
---|
64 | #include "prthread.h"
|
---|
65 | #include <sys/types.h>
|
---|
66 | #include <unistd.h>
|
---|
67 |
|
---|
68 | void SegFault(void *unused)
|
---|
69 | {
|
---|
70 | int *p = 0;
|
---|
71 |
|
---|
72 | printf("The grandchild sproc has pid %d.\n", getpid());
|
---|
73 | printf("The grandchild sproc will get a segmentation fault and die.\n");
|
---|
74 | printf("The parent and child sprocs should be killed after the "
|
---|
75 | "grandchild sproc dies.\n");
|
---|
76 | printf("Use 'ps' to make sure this is so.\n");
|
---|
77 | fflush(stdout);
|
---|
78 | /* Force a segmentation fault */
|
---|
79 | *p = 0;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void NeverStops(void *unused)
|
---|
83 | {
|
---|
84 | int i = 0;
|
---|
85 |
|
---|
86 | printf("The child sproc has pid %d.\n", getpid());
|
---|
87 | printf("The child sproc won't stop on its own.\n");
|
---|
88 | fflush(stdout);
|
---|
89 |
|
---|
90 | /* create the grandchild sproc */
|
---|
91 | PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
|
---|
92 | PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
|
---|
93 |
|
---|
94 | while (1) {
|
---|
95 | i++;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | int main()
|
---|
100 | {
|
---|
101 | int i= 0;
|
---|
102 |
|
---|
103 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
---|
104 |
|
---|
105 | printf("The parent sproc has pid %d.\n", getpid());
|
---|
106 | printf("The parent sproc won't stop on its own.\n");
|
---|
107 | fflush(stdout);
|
---|
108 |
|
---|
109 | /* create the child sproc */
|
---|
110 | PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
|
---|
111 | PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
|
---|
112 |
|
---|
113 | while (1) {
|
---|
114 | i++;
|
---|
115 | }
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | #endif /* IRIX */
|
---|