Solved

CTRL-C While a process is getting executed marks it as changed

Posted on 1998-07-07
9
224 Views
Last Modified: 2010-03-30
Env:- windows

I am calling
ftp -n -s:filename
from within the java program
( exec( "ftp -n -s:somefile.tar.gz ") )
now the problem is while the ftp is in progress
if the user presses ctrl-c windows will come out of the program
but it will mark the file (been ftp'd) as been modified and wont allow me to delete
the file till garbage collector runs how to overcome this problem.
0
Comment
Question by:gopalindia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Accepted Solution

by:
aziz061097 earned 50 total points
ID: 1225293
If you want to force a garbage collection you can call the method System.gc() . If your question is different from just getting the Garbage collector started , please give more details. How are you calling the ftp command (is it programmatically using ftp client or by invoking the shell ftp command ?
0
 

Author Comment

by:gopalindia
ID: 1225294
c:\java programname
--ftp in progress.
--ctrl -c
c:\ prompt.

I am calling the dos shell.
CTRL-C is an higher level interrupt which I cannot trap inside the java application and therefore i cannot call system.gc() as it will cause it to come out of the shell because of which i cannot delete the file or rename it or call my ftp program again until the garbage collector has collected the process and released the file.

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1225295
Pressing Ctrl-C kills the Java program or only kills the FTP process it started?
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

Author Comment

by:gopalindia
ID: 1225296
It kills the java program and ftp process.
But leaves a flag in the windows OS saying that the file is been modified and no other user should modify it and the result is you cannot move or rename or do anything with the file for say about half an hour or so depending upon when windows will reset the flag for the file and all subsequent operations to ftp the file will fail as you dont have write permissions to the file.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1225297
Sounds like you need to do some cleanup in your code. First of all, you can call process.waitFor(), after you exeute exec() method. The former method blocks the thread until the process you started is finished. There you can clean up after the process (close all files, streams etc). Even more foolproof techinqueis to have a finalize method where you do similar cleanup. Garbage collector calls it before the program exits. (Since your java program gets killed, I do not think the problem is in the GC timing. I think you simply fail to release the resources in your program).  And yet another mechanism is to put a try/catch/finally block in your code where finally block will do the cleanup no matter what happens inside the try or catch blocks.
0
 

Author Comment

by:gopalindia
ID: 1225298
Dear friend Thanx for responding I am aware of
try
catch
finally part
The thing is CTRL-C will not be caught in try catch.
here is my program.
   
  r_ftp = Runtime.getRuntime();
      String s_ftp_ex = new String( "ftp -n -s:"+s_cnl_tmp_txt );
      p_ftp=r_ftp.exec ( s_ftp_ex );
      p_ftp.waitFor();
      rtn_val=p_ftp.exitValue();
      p_ftp.destroy();
    catch (IOException e)
    {
      System.out.println("IOException "+e );
    }    
    catch (InterruptedException e)
    {
      System.out.println("Interrupted "+e );
     }
    catch ( Exception e )
    {
      System.out.println("Something wrong"+e );
    }
    finally
    {
      p_ftp.destroy();
    }

Now the thing is it is a big file which is to be ftp'd and it waits till the ftp is over
and if you press ctrl-c in between you cannot modify the file nor try to do ftp again till it is reset by windows flag.

0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1225299
Hi Gopal,

        You can atleast call System.gc() in the finally clause .

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1225300
What do you mean by "reset by window flag". What exactly happens to the file you are trying to FTP when you press Ctrl-C? What happens if you simply start run FTP command from the command line (outside of Java program) and try Ctrl-C? Will teh same thing happen? (If so, Java have nothing to do with it, it is the way "ftp" is implemented).
0
 

Author Comment

by:gopalindia
ID: 1225301
Thank you guys for replying to my question:-
Aziz:- I cant call system.gc() because it is not trapped by the java Exception at all and no way I can call system.gc.

msmolyak:-Had ftp been the problem then why I can do the same thing within  perl and not with java.

When i try ftp from other programs everything goes fine and moreover I have found the answer it is Java has got a package
sun.net which i am using...
Thank you guys.

Thank you

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question