sproc_ch.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
0N/A/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2362N/A/* ***** BEGIN LICENSE BLOCK *****
0N/A * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0N/A *
0N/A * The contents of this file are subject to the Mozilla Public License Version
0N/A * 1.1 (the "License"); you may not use this file except in compliance with
2362N/A * the License. You may obtain a copy of the License at
0N/A * http://www.mozilla.org/MPL/
2362N/A *
0N/A * Software distributed under the License is distributed on an "AS IS" basis,
0N/A * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0N/A * for the specific language governing rights and limitations under the
0N/A * License.
0N/A *
0N/A * The Original Code is the Netscape Portable Runtime (NSPR).
0N/A *
0N/A * The Initial Developer of the Original Code is
0N/A * Netscape Communications Corporation.
0N/A * Portions created by the Initial Developer are Copyright (C) 1998-2000
0N/A * the Initial Developer. All Rights Reserved.
2362N/A *
2362N/A * Contributor(s):
2362N/A *
0N/A * Alternatively, the contents of this file may be used under the terms of
0N/A * either the GNU General Public License Version 2 or later (the "GPL"), or
0N/A * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0N/A * in which case the provisions of the GPL or the LGPL are applicable instead
0N/A * of those above. If you wish to allow use of your version of this file only
0N/A * under the terms of either the GPL or the LGPL, and not to allow others to
0N/A * use your version of this file under the terms of the MPL, indicate your
0N/A * decision by deleting the provisions above and replace them with the notice
0N/A * and other provisions required by the GPL or the LGPL. If you do not delete
0N/A * the provisions above, a recipient may use your version of this file under
0N/A * the terms of any one of the MPL, the GPL or the LGPL.
0N/A *
0N/A * ***** END LICENSE BLOCK ***** */
0N/A
0N/A/*
0N/A * Test sproc_ch.c
0N/A *
0N/A * The purpose of this test and the sproc_p.c test is to test the shutdown
0N/A * of all the IRIX sprocs in a program when one of them dies due to an error.
0N/A *
0N/A * There are three sprocs in this test: the parent, the child, and the
0N/A * grandchild. The parent and child sprocs never stop on their own.
0N/A * The grandchild sproc gets a segmentation fault and dies. You should
0N/A * You should use "ps" to see if the parent and child sprocs are killed
0N/A * after the grandchild dies.
0N/A */
0N/A
0N/A#include "prinit.h"
0N/A#include <stdio.h>
0N/A
0N/A#if !defined(IRIX)
0N/A
0N/Aint main()
0N/A{
0N/A printf("This test applies to IRIX only.\n");
0N/A return 0;
0N/A}
0N/A
0N/A#else /* IRIX */
0N/A
0N/A#include "prthread.h"
0N/A#include <sys/types.h>
0N/A#include <unistd.h>
0N/A
0N/Avoid SegFault(void *unused)
0N/A{
0N/A int *p = 0;
0N/A
0N/A printf("The grandchild sproc has pid %d.\n", getpid());
0N/A printf("The grandchild sproc will get a segmentation fault and die.\n");
0N/A printf("The parent and child sprocs should be killed after the "
0N/A "grandchild sproc dies.\n");
0N/A printf("Use 'ps' to make sure this is so.\n");
0N/A fflush(stdout);
0N/A /* Force a segmentation fault */
0N/A *p = 0;
0N/A}
0N/A
0N/Avoid NeverStops(void *unused)
0N/A{
0N/A int i = 0;
0N/A
0N/A printf("The child sproc has pid %d.\n", getpid());
0N/A printf("The child sproc won't stop on its own.\n");
0N/A fflush(stdout);
0N/A
0N/A /* create the grandchild sproc */
0N/A PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
0N/A PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
0N/A
0N/A while (1) {
0N/A i++;
0N/A }
0N/A}
0N/A
0N/Aint main()
0N/A{
0N/A int i= 0;
0N/A
0N/A PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
0N/A
0N/A printf("The parent sproc has pid %d.\n", getpid());
0N/A printf("The parent sproc won't stop on its own.\n");
0N/A fflush(stdout);
0N/A
0N/A /* create the child sproc */
0N/A PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
0N/A PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
0N/A
0N/A while (1) {
0N/A i++;
0N/A }
0N/A return 0;
0N/A}
0N/A
0N/A#endif /* IRIX */
0N/A