B9:Java Program to display the list of devices connected to your system including the physical names and its instance number.
Program:
import
java.io.*;
class
ListDevice
{
public static void main(String args[])
throws IOException
{
String line = null;
Process ps =
Runtime.getRuntime().exec("lspci");
BufferedReader reader =
new BufferedReader(new InputStreamReader(ps.getInputStream()));
System.out.println("Listing
Devices using lspci command ");
while((line =
reader.readLine())!= null)
{
System.out.println(line);
}
ps =
Runtime.getRuntime().exec("cat /proc/devices");
reader = new
BufferedReader(new InputStreamReader(ps.getInputStream()));
System.out.println("Reading
Device File ");
while((line =
reader.readLine())!= null)
{
System.out.println(line);
}
}
}
Output:
[student@localhost ~]$
javac ListDevice.java
[student@localhost ~]$
java ListDevice
Listing Devices using
lspci command
00:00.0 Host bridge:
Intel Corporation 4 Series Chipset DRAM Controller (rev 03)
00:01.0 PCI bridge:
Intel Corporation 4 Series Chipset PCI Express Root Port (rev 03)
00:02.0 VGA compatible
controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller
(rev 03)
00:02.1 Display
controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller
(rev 03)
00:1b.0 Audio device:
Intel Corporation NM10/ICH7 Family High Definition Audio Controller (rev 01)
00:1c.0 PCI bridge:
Intel Corporation NM10/ICH7 Family PCI Express Port 1 (rev 01)
00:1d.0 USB controller:
Intel Corporation NM10/ICH7 Family USB UHCI Controller #1 (rev 01)
00:1d.1 USB controller:
Intel Corporation NM10/ICH7 Family USB UHCI Controller #2 (rev 01)
00:1d.2 USB controller:
Intel Corporation NM10/ICH7 Family USB UHCI Controller #3 (rev 01)
00:1d.3 USB controller:
Intel Corporation NM10/ICH7 Family USB UHCI Controller #4 (rev 01)
00:1d.7 USB controller:
Intel Corporation NM10/ICH7 Family USB2 EHCI Controller (rev 01)
00:1e.0 PCI bridge:
Intel Corporation 82801 PCI Bridge (rev e1)
00:1f.0 ISA bridge:
Intel Corporation 82801GB/GR (ICH7 Family) LPC Interface Bridge (rev 01)
00:1f.1 IDE interface:
Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01)
00:1f.2 IDE interface:
Intel Corporation NM10/ICH7 Family SATA Controller [IDE mode] (rev 01)
00:1f.3 SMBus: Intel
Corporation NM10/ICH7 Family SMBus Controller (rev 01)
02:00.0 Ethernet
controller: Broadcom Corporation NetLink BCM57780 Gigabit Ethernet PCIe (rev
01)
Reading Device
File
Character devices:
1 mem
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
7 vcs
10 misc
13 input
14 sound
21 sg
29 fb
99 ppdev
116 alsa
128 ptm
136 pts
162 raw
Block devices:
259 blkext
7 loop
8 sd
9 md
11 sr
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
0 comments:
Post a Comment