This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to free CPU utilised?

 
yathish Gatty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9319
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic