Java cannot access /proc filesystem on Linux

F

FET

Hi everybody,
This is pretty strange. Java seems unable to recognise the /proc file
system on linux. The same thing can be accessed from C++ programs
without any special programming logic, just simple file handling
calls.
I basically want to find out if a process is running or it has stopped
and display the status to the user. So I figured that using the /proc
filesystem, I can simply check the PID of the process (which is stored
in a known location on the disk by the process itself).
But I am unable to do this through java.
Can anyone please help me out?
Thanks in advance.
Regards.
 
G

Gordon Beaton

This is pretty strange. Java seems unable to recognise the /proc
file system on linux. The same thing can be accessed from C++
programs without any special programming logic, just simple file
handling calls.

I basically want to find out if a process is running or it has
stopped and display the status to the user. So I figured that using
the /proc filesystem, I can simply check the PID of the process
(which is stored in a known location on the disk by the process
itself). But I am unable to do this through java. Can anyone please
help me out?

Of course it's possible from Java using simple file handing calls.
Maybe you've done something strange? What exact problems are you
having (what are the symptoms)?

This works for me:

File f = new File("/proc/123");

if (f.exists()) {
System.out.println("process 123 exists");
}
else {
System.out.println("process 123 does not exist");
}

Similarly, you can use a FileReader to open and read any of the files
in the corresponding directory.

/gordon
 
F

FET

Hi,
Thank you for your reply. yes, I was using DataInputStream and it
didn't work. Then I used FileReader and it worked perfectly.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top