Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4149411

1.1.6 java hangs when the parent process is killed after a native fork call

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.6
    • Fix Version/s: None
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description


      The example below uses JNI interface to call a native function with
      in turn calls fork() and then destroys the parent process.
      This causes 1.1.6 java hang after the first native call but works
      for (SunSoft) java 1.1.5 and 1.1.4.

      $ cat testfork.c
      #include "jni.h"
      #include <stdio.h>
      #include <string.h>

      jstring JNICALL JNIEXPORT Java_TheButton_EstablishConnection(
           JNIEnv *env, jclass cl)
      {
          char * p;
          int pid;
          printf("About to call fork\n");
          pid = fork();
          if (pid == -1) /* failure */
             printf("execution failed: unable to fork");
          else if (pid != 0) //parent
          {
             printf("the parent process is killed\n");
             exit(1);
          } else //child
          printf("Child process stays ");
          return((*env)->NewStringUTF(env, " "));
      }

      $ cat makefile
      JDK1.1.6_HOME = /mde/apps/ilya/java/jdk1.1.6
      libnative.so: testfork.c
              cc -xCC -I${JDK1.1.6_HOME}/include -I${JDK1.1.6_HOME}/include/solaris -I. -c testfork.c; cc -o libnative.so -G -KPIC -hlibnative.so testfork.o;

      $ cat TestFork.java
      import java.awt.*;
      import java.awt.event.*;

      public class TestFork {
          private Frame f;
          private Panel p2;

          public static void main(String args[]) {
              TestFork gui = new TestFork();
              gui.start();
          }

          public void start() {
              f = new Frame("Level 1 Lab");
              p2 = new Panel();
              p2.add(new TheButton("Test"));
              p2.add(new TheButton("Exit"));

              f.add(p2, "Center");
              f.setSize(200,100);
              f.setBackground(Color.white);
              f.setVisible(true);

          }
      }

      class TheButton extends Button {
        public static native String EstablishConnection();
         static
         {
           System.loadLibrary("native");
         }

          TheButton (String s) {
              super (s);
          }
          public boolean action (Event e, Object o) {
              if ("Test".equals(o)) {
                  String errString;
                  System.out.println("About to make native call");
                  errString = EstablishConnection();
                  System.out.println("Returned from native call");
                  return true;
              } else if ("Exit".equals(o)) {
                  System.exit(0);
              } else {
                  return false;
              }
              return true;
          }
      }



      This works with

      $ java -version
      java version "1.1.4"
      $ java -version
      java version "1.1.5"

      and causes hangs with

      $ ../../jdk1.1.6/bin/java -version
      java version "1.1.6"

        Attachments

          Activity

            People

            Assignee:
            never Tom Rodriguez
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: