Everything in both
/sys and /proc has the following very-important characteristic:
it doesn't really "exist."
Everything that you "see" in either of these two "directories" is actually
something that describes the operating-system itself. In other words, when you "ask for a list of the 'files' and 'directories' in" either of these two "locations," Linux actually
generates what you see ... "on the fly!"
For instance: try
dir /proc. In this "directory" you will find a slew of "sub-directories" whose names are numbers. (Say...
/proc/3569.) "Inside of" each of these "sub-directories" you will find other "files" and "directories."
So far, so good?
Well... the truth is,
/proc/3569 does
not correspond to any physical resource: it corresponds to a currently-running process, #3569. The "files and subdirectories" within that "directory" correspond to various characteristics of that process. When process #3569 ceases to exist, so will the "directory" and all of its "contents."
This peculiar strategy enables commands like
ps ("process list") to do their magic without being "magical." All they need to do is to look at the "contents of"
/proc.
To make a long story short,
/sys works in exactly the same way. This "directory" allows the Linux system to expose useful characteristics of itself in exactly the same way that
/proc allows it to expose useful characteristics of the process-table.
This strategy is actually very, very clever. You see, "ordinary" programs already know how to deal with "files and directories." It doesn't take any "special voodoo" for them to do
that. But if they wanted to take a peek at the process-table??? If they wanted to take a peek at the current characteristics of "Linux itself?"
Major Voodoo!! Not! Instead of subjecting these programs to the 'necessity' of performing 'major voodoo,' Linux provides a mechanism that exposes the necesssary 'voodoo' information "as though it were 'just' an ordinary file."
And
that, I assure you,
is "
real voodoo!"