0

I need to read PCI device information from files. But it gives unusable output when I use command like that:

cat /proc/bus/pci/05/00.0

Output:

�h��

How could I fix this?

OS: Debian-like Linux x64, Kenel 4.19

2 Answers 2

2

Not every file under /proc/ contains text.

/proc/bus/pci/05/00.0 (and similar files) contain binary data, not text. They're not meant to be displayed to a terminal, they're meant to be read by a program that understands the binary data format (which will be documented somewhere in the kernel documentation. or source code, at least).

If you want to see what's in it, you can use hexdump aka hd:

$ hd /proc/bus/pci/05/00.0
00000000  00 10 72 00 07 04 10 00  03 00 07 01 10 00 00 00  |..r.............|
00000010  01 c0 00 00 04 00 6c d2  00 00 00 00 04 00 28 d2  |......l.......(.|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 10 40 30  |..............@0|
00000030  00 00 40 fe 50 00 00 00  00 00 00 00 0a 01 00 00  |[email protected]...........|
00000040

Your output will probably be different because you almost certainly have a different PCI-e device at 05:00.0

2

If you are looking for e.g. PCI vendor/device identifiers, you could use the /sys/bus/pci/... directory tree instead:

for i in /sys/bus/pci/devices/*
do 
    printf "Device ${i##*/}: vendor %s, device %s\n" "$(< $i/vendor)" "$(< $i/device)"
done

I think the /sys directory hierarchy was created as /proc was becoming cluttered by miscellaneous (non-process-related) system information in random hard-to-parse formats, and the kernel developers did not like that, and so /sys has a more strict requirement about the virtual files being easy to parse.

So you might want to check if whatever information you're trying to find is available under /sys first before going to /proc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .