home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / sproc_ch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.8 KB  |  101 lines

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