2

I want to know what is the /proc and what kind of stuffs included in that? And if the /proc store in RAM or Hard drive?

Thanks

2

Taken from here:

/proc is very special in that it is also a virtual filesystem. It's sometimes referred to as a process information pseudo-file system. It doesn't contain 'real' files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc).

again, from the same site:

The /proc filesystem contains a illusionary filesystem. It does not exist on a disk. Instead, the kernel creates it in memory.

So, to answer your questions:

  1. /proc contains information about your system and peripherals, it can also be used to control kernel behaviour by writing to it. Details about the content of each entry can be found at the first link.
    For example, you can get your CPU information by inspecting /proc/cpuinfo:

    cat /proc/cpuinfo
    

    Or you can change options like IP forwarding:

    echo "1" > /proc/sys/net/ipv4/ip_forward # enables IP forwading
    echo "0" > /proc/sys/net/ipv4/ip_forward # disables IP forwading
    
  2. It's not a real filesystem. It is a representation of the kernel inner structures. So, it's not really stored anywhere, but you can say that its contents are stored in the kernel memory (so "RAM").

Most of the operations you can perform directly on the /proc filesystem can (and really, should) be performed via the sysctl utility (manpage).

| improve this answer | |
1

To quote kernel.org documentation :

The proc file system acts as an interface to internal data structures in the kernel. It can be used to obtain information about the system and to change certain kernel parameters at runtime (sysctl).

Kernel itself is loaded in memory. Along with sockfs and pipefs, procfs is a virtual filesystem. The directory /proc you see on the disk is not permanent - data in this directory remains there only for the duration of the system running. Once you shut it down, the data does not remain on disk and the directory will be empty. The directory itself merely serves as mountpoint for in-kernel filesystem.

As for information that it contains, the Wikipedia article on procfs describes it succinctly:

The proc filesystem (procfs) is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure, providing a more convenient and standardized method for dynamically accessing process data held in the kernel than traditional tracing methods or direct access to kernel memory.

...

The proc filesystem provides a method of communication between kernel space and user space. For example, the GNU version of the process reporting utility ps uses the proc file system to obtain its data, without using any specialized system calls.

Among other things, it's a convenient method for processes to know what resources are available to them. For instance, if you run strace -e open,openat df you will see that it opens /proc/self/mountinfo to obtain information about mountpoints available to it running under your username:

openat(AT_FDCWD, "/proc/self/mountinfo", O_RDONLY) = 3
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.