Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Child process inherits socket handlers

Thread view: 
evgchech - 21 Feb 2007 08:55 GMT
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
Knute Johnson - 21 Feb 2007 16:14 GMT
> Hello Everyone
> I am using Java Runtime.exec to create child process (Internet
[quoted text clipped - 11 lines]
>
> Thanks in advance

Are you sure that the parent is actually stopped?

Signature

Knute Johnson
email s/nospam/knute/

hiwa - 23 Feb 2007 01:44 GMT
> Hello Everyone
> I am using Java Runtime.exec to create child process (Internet
[quoted text clipped - 11 lines]
>
> 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
evgchech - 26 Feb 2007 09:42 GMT
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()
   }
Esmond Pitt - 27 Feb 2007 02:57 GMT
Cannot reproduce. Is what you really mean that your UDPListenerThread
never exits?

>  public class UDPListener extends Thread{
>
[quoted text clipped - 3 lines]
>                 return;
>             }

How is that ever going to get executed?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.