nsprpub/pr/tests/sproc_p.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/sproc_p.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Test sproc_p.c
    1.11 + *
    1.12 + * The purpose of this test and the sproc_ch.c test is to test the shutdown
    1.13 + * of all the IRIX sprocs in a program when one of them dies due to an error.
    1.14 + *
    1.15 + * In this test, the parent sproc gets a segmentation fault and dies.
    1.16 + * The child sproc never stops on its own.  You should use "ps" to see if
    1.17 + * the child sproc is killed after the parent dies.
    1.18 + */
    1.19 +
    1.20 +#include "prinit.h"
    1.21 +#include <stdio.h>
    1.22 +
    1.23 +#if !defined(IRIX)
    1.24 +
    1.25 +int main(int argc, char **argv)
    1.26 +{
    1.27 +    printf("This test applies to IRIX only.\n");
    1.28 +    return 0;
    1.29 +}
    1.30 +
    1.31 +#else  /* IRIX */
    1.32 +
    1.33 +#include "prthread.h"
    1.34 +#include <sys/types.h>
    1.35 +#include <unistd.h>
    1.36 +
    1.37 +void NeverStops(void *unused)
    1.38 +{
    1.39 +    int i = 0;
    1.40 +
    1.41 +    printf("The child sproc has pid %d.\n", getpid());
    1.42 +    printf("The child sproc won't stop on its own.\n");
    1.43 +    fflush(stdout);
    1.44 +
    1.45 +    /* I never stop */
    1.46 +    while (1) {
    1.47 +	i++;
    1.48 +    }
    1.49 +}
    1.50 +
    1.51 +int main()
    1.52 +{
    1.53 +    int *p = 0;
    1.54 +
    1.55 +    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    1.56 +
    1.57 +    printf("The parent sproc has pid %d.\n", getpid());
    1.58 +    printf("The parent sproc will first create a child sproc.\n");
    1.59 +    printf("Then the parent sproc will get a segmentation fault and die.\n");
    1.60 +    printf("The child sproc should be killed after the parent sproc dies.\n");
    1.61 +    printf("Use 'ps' to make sure this is so.\n");
    1.62 +    fflush(stdout);
    1.63 +
    1.64 +    PR_CreateThread(PR_USER_THREAD, NeverStops, NULL,
    1.65 +	    PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
    1.66 +
    1.67 +    /* Force a segmentation fault */
    1.68 +    *p = 0;
    1.69 +    return 0;
    1.70 +}
    1.71 +
    1.72 +#endif /* IRIX */

mercurial