Child process inherits socket handlers

E

evgchech

Hello Everyone
I am using Java Runtime.exec to create child process (Internet
Explorer for this meter).
The parent process binds to UPD socket before creating the child
process.
The strange phenomenon is when parent process shuts down the socket is
still busy and it is being released only after i shut down the child
process.
The work around i came up with is to add to the parent process
shutdown hook, where it can invoke the destroy method upon the Process
instance returned from exec invocation.
Is there any other solution in (JDK 1.4) where i can cerate a child
process without passing to it parent open handlers.

Thanks in advance
 
K

Knute Johnson

evgchech said:
Hello Everyone
I am using Java Runtime.exec to create child process (Internet
Explorer for this meter).
The parent process binds to UPD socket before creating the child
process.
The strange phenomenon is when parent process shuts down the socket is
still busy and it is being released only after i shut down the child
process.
The work around i came up with is to add to the parent process
shutdown hook, where it can invoke the destroy method upon the Process
instance returned from exec invocation.
Is there any other solution in (JDK 1.4) where i can cerate a child
process without passing to it parent open handlers.

Thanks in advance

Are you sure that the parent is actually stopped?
 
H

hiwa

Hello Everyone
I am using Java Runtime.exec to create child process (Internet
Explorer for this meter).
The parent process binds to UPD socket before creating the child
process.
The strange phenomenon is when parent process shuts down the socket is
still busy and it is being released only after i shut down the child
process.
The work around i came up with is to add to the parent process
shutdown hook, where it can invoke the destroy method upon the Process
instance returned from exec invocation.
Is there any other solution in (JDK 1.4) where i can cerate a child
process without passing to it parent open handlers.

Thanks in advance

Post a small demo code that is generally compilable, runnable and
could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html
and http://www.yoda.arachsys.com/java/newsgroups.html
 
E

evgchech

private void button2ActionPerformed(java.awt.event.ActionEvent evt)
{
UDPListener listener = new UDPListener();
listener.setName("UDPListener");
listener.start();
}

//open IE
private void button1ActionPerformed(java.awt.event.ActionEvent
evt) {
try {
p =
Runtime.getRuntime().exec("C:/Program Files/
Internet Explorer/IEXPLORE.EXE");
} catch (IOException ex) {
ex.printStackTrace();
}
}

public class UDPListener extends Thread{

public void run() {
int bufSz = 1399;
if(bufSz == 0) {
return;
}

//
// get a buffer for the datagrams
//
byte[] buf = new byte[bufSz];
DatagramSocket m_comm=null;
try {
m_comm = new DatagramSocket(1166);
m_comm.setSoTimeout(4000);
} catch (SocketException ex) {
ex.printStackTrace();
}
DatagramPacket m_pkt = new DatagramPacket(buf, bufSz);


while(true) {
try {
//
// reset the packet's length
//
m_pkt.setLength(bufSz);
m_comm.receive(m_pkt);
} catch(InterruptedIOException ioe) {
// If m_isClosing flag has been set we will exit
the loop
continue;
} catch(Exception e) {
System.out.println("Caught Exception: " +
e.getMessage());
e.printStackTrace(System.out);
}
}
} // end run()
}
 
E

Esmond Pitt

evgchech wrote:

Cannot reproduce. Is what you really mean that your UDPListenerThread
never exits?
public class UDPListener extends Thread{

public void run() {
int bufSz = 1399;
if(bufSz == 0) {
return;
}

How is that ever going to get executed?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,138
Latest member
NevilleLam
Top