• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to free CPU utilised?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am running an .exe file using :

Runtime rt = Runtime.getRuntime();

Process proc = rt.exec(cmd);

Where cmd is String to execute .exe file.

When I run this .exe file continuosly.Say after executing 1000 times it hangs.

When I checked in windows task manager it showed .exe 100% CPU utilised.Then I had to manually release the resource.

How can I avoid this from happening?

Is there a way by which I can programatically release the 100% CPU utilised resource.

Thank You,

With regards,

Yathish
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
proc.destroy() should kill the process, according to the javadoc: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html
 
yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply,

I have done as you said

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);
int ret=proc.waitFor();
proc.destroy();

But this still it hangs.

Thank you.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's not much point doing destroy() after waitFor() has returned. When the waitFor() returns, the process has finished anyway. The point of destroy() is to request a process that's still running to terminate.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you really exec-ing without consuming the System out and err character streams generated by the Process?
Perhaps you are throwing away the information that could tell you what is going on.
Bill
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Bill said.

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.


java.lang.Process
 
yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tried to handle the Standard error and standard inputstream by using the following code but this still hangs.Just verify whether this was the solution you specified if not please help me out in this.

The code I have implemented is as follows:



Please help me out in this .

Thank you.

From ,

Yathish

[added code tags to preserve formatting - Ilja]
[ April 26, 2005: Message edited by: Ilja Preuss ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks reasonable for catching and displaying the system out and err character streams - now, are you seeing anything unexpected or getting any error codes?

Looking back at your original post:

When I run this .exe file continuosly.Say after executing 1000 times it hangs.


The following questions occur to me:
1. Are you waiting for the end of one Process before repeating or trying to fire off 1000 execs at one time?
2. Watching the task manager - does it show gradual increase in CPU utilization or is the change sudden? How about memory utilization/
3. This proces you are execing - what system resources does it use? File handles, Graphic contexts, DB connections, etc.

Bill
 
yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The code does not display any error codes.

I am waiting for one process to complete and then continuing with the next.i.e execing one at a time.

The change in cpu utilization is sudden.
As far as system memory utilization is concerned there are no issues.It remains constant throughout.

The .exe file i am using is filter.exe of Microsoftword 2000.

Thank you,

with regards,

Yathish
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that if this was my problem, I would insert a delay of at least a second between the end of one process and the next exec. I know that sounds strange, but I am suspecting that after you are getting the end of the process, Windows still has some cleaning up to do.
I know my WinXP systems sometimes seem to wander off and do a bunch of housekeeping stuff totally out of my control.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic