If i do cat /proc/asound/cards it lists all the sound card details from where proc gets this information.This file is continuously updating what if i want to make a manual entry
-
Very similar question on SuperUser: How does /proc/* work?. (Fair warning: the accepted, and by far highest-voted, answer is my own.) – user Sep 09 '13 at 12:18
2 Answers
That's because /proc
(and /sys
) are kernel interfaces. Nothing in there is a real file on disk. The information comes directly from the OS. The individual files are kind of like socket interfaces, and when you read them you are making a request for data.
The proc filesystem apparently originates with UNIX 8 (although the Linux implementation, like most other implementations, was cloned from Plan 9 from Bell Labs) and is in keeping with the "everything is a file" UNIX adage. It primarily represents individual running processes (the top level numbers are pids) but can, as you note, include some other stuff as well -- which overlaps on Linux with the more hardware oriented /sys
.
As a note, occasionally I see people looking for "better alternatives" to getting the proc information programmatically, where "better alternatives" means system calls like sysctl()
or ioctl()
. This seems to be rooted in the misconception that reading proc or sys files involves some I/O overhead like reading a regular file would. It doesn't, and while some OS's (FreeBSD, I think) have done the opposite, on Linux sysctl()
calls are depreciated:
From man 2 sysctl:
use of this system call has long been discouraged, and it is so unloved that it is likely to disappear in a future kernel version. Remove it from your programs now; use the /proc/sys interface instead.
So there you have it: on linux at least, procfs is the officially recommended source for info from the kernel. There are no "better alternatives".

- 14,951

- 87,661
- 30
- 204
- 262
The files in /proc
are not actually stored anywhere; when you try to read them, the kernel calls a function in the appropriate driver to get the file's contents.
In the case of /proc/asound/cards
, this ends up at the function snd_card_info_read, which generates its output from ALSA's internal sound card list.
You cannot add another entry without instantiating another sound card driver.

- 2,709
-
-
@ganeshredcobra : Not via
proc
, no. It is generally read-only -- it's for information, not configuration. – goldilocks Sep 09 '13 at 12:01 -
What if i want to create a custom device node like /dev/snd/custom_dev.Is there any method to create this other than using mknod.I want to create the dev file inside snd folder itself – ganeshredcobra Sep 09 '13 at 12:08
-
What do want to do with this device node? I'd guess you should write your own sound driver. – CL. Sep 09 '13 at 12:19