Reputation: 6229
I've recently been tasked with developing a program to monitor a bunch of hard drive information (serial, maker, type, etc) from multiple hard drives. In my initial research I found that this was pretty easy to do using some C# code and created a test program that way. Unfortunately, I'm required to use a linux OS which means c# is off the table.
I was curious if anyone knows, or could point me in the right direction of developing an app in Java/C/C++ that would achieve the same effect. I do know that if you use Java you have to use the JNI and you're using C/C++ at that point regardless.
Thanks.
Upvotes: 1
Views: 1011
Reputation: 3402
Depending on the exact information you need there might be no need to use JNI.
Linux make a lot of information about the hardware available in the sysfs and procfs virtual filesystems. For instance, you can find the harddisk model for the fist disk in /sys/block/sda/device/model, which you should be able to read in Java just like any other file.
Additionally you could look at the output of fdisk -l /dev/sda' and
hdparm -I /dev/sdawhich both provide quite a bit of information. You can call these using
Runtime.exec()` and parse the output.
Upvotes: 2
Reputation: 12538
I'm not aware of any Java libraries making your life easier, but if you want to implement an OS independent solution supporting different OSes you should have a look at java.lang.Runtime which enables you to execute external processes. You could maintain a map for each OS defining the (CLI) commands for retrieving the required information. It may be easier than implementing a bunch of native calls using JNI:
Process p = Runtime.getRuntime().exec("df -h");
p.waitFor();
InputStream is = p.getInputStream();
/* work with command line output... */
I know it's not a perfect solution, but you may want to have a look at it.
Upvotes: 1