home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / sproc_p.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.3 KB  |  83 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_p.c
  21.  *
  22.  * The purpose of this test and the sproc_ch.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.  * In this test, the parent sproc gets a segmentation fault and dies.
  26.  * The child sproc never stops on its own.  You should use "ps" to see if
  27.  * the child sproc is killed after the parent dies.
  28.  */
  29.  
  30. #include "prinit.h"
  31. #include <stdio.h>
  32.  
  33. #if !defined(IRIX)
  34.  
  35. int main()
  36. {
  37.     printf("This test applies to IRIX only.\n");
  38.     return 0;
  39. }
  40.  
  41. #else  /* IRIX */
  42.  
  43. #include "prthread.h"
  44. #include <sys/types.h>
  45. #include <unistd.h>
  46.  
  47. void NeverStops(void *unused)
  48. {
  49.     int i = 0;
  50.  
  51.     printf("The child sproc has pid %d.\n", getpid());
  52.     printf("The child sproc won't stop on its own.\n");
  53.     fflush(stdout);
  54.  
  55.     /* I never stop */
  56.     while (1) {
  57.     i++;
  58.     }
  59. }
  60.  
  61. int main()
  62. {
  63.     int *p = 0;
  64.  
  65.     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  66.  
  67.     printf("The parent sproc has pid %d.\n", getpid());
  68.     printf("The parent sproc will first create a child sproc.\n");
  69.     printf("Then the parent sproc will get a segmentation fault and die.\n");
  70.     printf("The child sproc should be killed after the parent sproc dies.\n");
  71.     printf("Use 'ps' to make sure this is so.\n");
  72.     fflush(stdout);
  73.  
  74.     PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
  75.         PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
  76.  
  77.     /* Force a segmentation fault */
  78.     *p = 0;
  79.     return 0;
  80. }
  81.  
  82. #endif /* IRIX */
  83.