nsprpub/pr/tests/sproc_ch.c

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     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/. */
     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  */
    19 #include "prinit.h"
    20 #include <stdio.h>
    22 #if !defined(IRIX)
    24 int main(int argc, char **argv)
    25 {
    26     printf("This test applies to IRIX only.\n");
    27     return 0;
    28 }
    30 #else  /* IRIX */
    32 #include "prthread.h"
    33 #include <sys/types.h>
    34 #include <unistd.h>
    36 void SegFault(void *unused)
    37 {
    38     int *p = 0;
    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 }
    50 void NeverStops(void *unused)
    51 {
    52     int i = 0;
    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);
    58     /* create the grandchild sproc */
    59     PR_CreateThread(PR_USER_THREAD, SegFault, NULL,
    60 	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    62     while (1) {
    63 	i++;
    64     }
    65 }
    67 int main()
    68 {
    69     int i= 0;
    71     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    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);
    77     /* create the child sproc */
    78     PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
    79 	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    81     while (1) {
    82 	i++;
    83     }
    84     return 0;
    85 }
    87 #endif  /* IRIX */

mercurial