Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: From: GALLWEY Martin To: "'cygwin AT cygwin DOT com'" Subject: Using forking cygwin programmes with JNI Date: Wed, 6 Aug 2003 19:47:40 +1000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C35BFF.C6D51FB0" Note-from-DJ: This may be spam ------_=_NextPart_000_01C35BFF.C6D51FB0 Content-Type: text/plain; charset="iso-8859-1" Hi there, I've got a Java programme which needs to read and write to the stdin and stdout of a native programme. On Linux, I've used /dev/ptmx and then forked and exec'd to give myself a single file descriptor which I can use to both read and write to the child process. I would like to do the same on Windows with Cygwin, but fork fails with the error message 'Fork failed because of Resource temporarily unavailable' when called via JNI. The same code called outside of the JVM works fine. On Linux it works both inside and outside the JVM. I've attached a simple programme to demonstrate this. If you follow these steps, you can re-produce the problem: gcc -shared HelloWorld.c -o hello.dll javac HelloWorld.java java HelloWorld For me, using Cygwin 1.3.22-1 and Sun's JDK version 1.4.1_03-b02, I get the following output: C:\CYGWIN\HOME\ADMINI~1\JNI>java HelloWorld Usage: java [-options] class [args...] (to execute a class) or java -jar [-options] jarfile [args...] (to execute a jar file) where options include: -dsa | -disablesystemassertions disable system assertions 101 [main] ? 2044 sync_with_child: child 1420(0x3F4) died before initialization with status code 0x1 436 [main] ? 2044 sync_with_child: *** child state waiting for longjmp Fork failed because of Resource temporarily unavailable I've tried various methods of working around this problem using windows' 'CreateProcess' API method and lots of other stuff, but nothing works as well as pseudo terminal/fork/exec does on Linux. Has anyone got any suggestions? Thank you, Martin IMPORTANT NOTICE: This e-mail and any attachment to it is intended only to be read or used by the named addressee. It is confidential and may contain legally privileged information. No confidentiality or privilege is waived or lost by any mistaken transmission to you. If you receive this e-mail in error, please immediately delete it from your system and notify the sender. You must not disclose, copy or use any part of this e-mail if you are not the intended recipient. The RTA is not responsible for any unauthorised alterations to this e-mail or attachment to it. ------_=_NextPart_000_01C35BFF.C6D51FB0 Content-Type: application/octet-stream; name="HelloWorld.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="HelloWorld.c" #include =0A= #include =0A= #include =0A= #include "HelloWorld.h"=0A= =0A= =0A= JNIEXPORT void JNICALL =0A= Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) =0A= {=0A= switch (fork () )=0A= {=0A= case -1:=0A= fprintf ( stderr, "Fork failed because of %s\n", strerror ( errno ) = );=0A= break;=0A= case 0:=0A= fprintf ( stderr, "Parent says hi\n" );=0A= break;=0A= default:=0A= fprintf ( stderr, "Child says hi\n" );=0A= }=0A= }=0A= ------_=_NextPart_000_01C35BFF.C6D51FB0 Content-Type: application/octet-stream; name="HelloWorld.h" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="HelloWorld.h" /* DO NOT EDIT THIS FILE - it is machine generated */=0A= #include =0A= /* Header for class HelloWorld */=0A= =0A= #ifndef _Included_HelloWorld=0A= #define _Included_HelloWorld=0A= #ifdef __cplusplus=0A= extern "C" {=0A= #endif=0A= /*=0A= * Class: HelloWorld=0A= * Method: displayHelloWorld=0A= * Signature: ()V=0A= */=0A= JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld=0A= (JNIEnv *, jobject);=0A= =0A= #ifdef __cplusplus=0A= }=0A= #endif=0A= #endif=0A= ------_=_NextPart_000_01C35BFF.C6D51FB0 Content-Type: application/octet-stream; name="HelloWorld.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="HelloWorld.java" class HelloWorld =0A= {=0A= static public native void displayHelloWorld();=0A= =0A= static =0A= {=0A= try=0A= {=0A= System.loadLibrary("hello");=0A= }=0A= catch ( UnsatisfiedLinkError aError )=0A= {=0A= System.out.println ( "Couldn't find the native library " + = aError.getMessage() );=0A= }=0A= catch ( SecurityException aError )=0A= {=0A= System.out.println ( "Wasn't allowed to load the native library " + = aError.getMessage() );=0A= }=0A= }=0A= =0A= public static void main(String[] args) =0A= {=0A= displayHelloWorld();=0A= }=0A= }=0A= =0A= =0A= ------_=_NextPart_000_01C35BFF.C6D51FB0 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ------_=_NextPart_000_01C35BFF.C6D51FB0--