4

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

ganeshredcobra
  • 331
  • 1
  • 3
  • 9

2 Answers2

4

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".

strugee
  • 14,951
goldilocks
  • 87,661
  • 30
  • 204
  • 262
1

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.

CL.
  • 2,709