close Unix file descriptor

Hi,

I have a process running to execute a command and it opens a file to read. The command will be run every minute, at some point it ran out file descriptor. How could I solve this problem? the code as below...

cmd = "generateTable -f prod.conf";

Process p = Runtime.getRuntime().exec(cmd);

how could I close the file descriptor in this case?

Any help will be much appreciated...

thanks.

[431 byte] By [tvphana] at [2007-10-3 4:23:16]
# 1

Does the command execute in less than 1 minute? If it didn't, that would explain why the system runs out of file descriptors. Does the external command close the file? Again, another possibility. Finally, if everything is closing file descriptors correctly, and the command executes in a timely fashion, perhaps you actually need to increase the number of file descriptors available. Linux and i386 BSD use sysctl to change kernel parameters. Try 'man sysctl' on your system. If you don't have sysctl, well, I'm just out of ideas then.

Brian

brian@cubik.caa at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 2
File descriptors can be opened or closed with the exec command.exec 4>&-closes file descriptor 4 for output.exec 4<&-closes file descriptor 4 for input.
ValentineSmitha at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 3
thanks for all your inputs.but exec 4<& can be called in Java program, right?thx.
tvphana at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 4
I meant Java code to call that cmd?I am aware that exec can use on cmd line window but I am thinking of java code to call it...
tvphana at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 5

Are you saying this external process "generateTable" is opening file descriptors but not closing them?

When the process terminates, any file descriptors it had still open (if any) should be closed automatically by the OS.

Either way, that external process is responsible for closing its own file descriptors that it uses though, and there's nothing your app can or should do about its failure to do so.

I think your problem lies elsewhere, in light of the 2nd paragraph above.

warnerjaa at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 6
thanks for your reply.As thinking more about this, you are right. I think the file descriptor should be closed automatically by the OS after process is done... need to check again.thanks.
tvphana at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...
# 7
The Process has input and output streams which correspond to pipes under the hood. You need to read all the output till EOF then close both the input and the output streams.
ejpa at 2007-7-14 22:25:35 > top of Java-index,Java Essentials,Java Programming...