1

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.

Max
  • 5,799
  • 3
  • 20
  • 27
  • 1
    C# is not necessarily off the table. Heard about the Mono Project? – dario_ramos Sep 20 '11 at 13:24
  • 4
    How about `sudo fdisk -l` or `cat /proc/scsi/scsi`? No need to program anything! – Ishtar Sep 20 '11 at 13:30
  • @dario_ramos I have heard of the mono project, but I have to build a GUI for the program and my impression was that C# was very limited in that sense via Mono. Ishtar I assume you mean that I just call those commands through the System? – Max Sep 20 '11 at 13:42
  • Max: Yes, it's limited if you want to stick to WinForms or WPF. You can use Gtk, but if you wanna stick to Java, I think that @home's answer might help – dario_ramos Sep 20 '11 at 13:46

2 Answers2

2

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' andhdparm -I /dev/sdawhich both provide quite a bit of information. You can call these usingRuntime.exec()` and parse the output.

AVee
  • 3,348
  • 17
  • 17
1

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.

home
  • 12,468
  • 5
  • 46
  • 54
  • @Max: fyi: http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information – home Sep 20 '11 at 14:16