ls -rlth /proc/stat
-r--r--r-- 1 root root 0 Feb 21 04:25 /proc/stat
Although if we cat
it, its got enough contents.
ls -rlth /proc/stat
-r--r--r-- 1 root root 0 Feb 21 04:25 /proc/stat
Although if we cat
it, its got enough contents.
That's because it is a virtual file that has no predefined known size, the actual size, i.e. the amount of data returned will vary depending on when you read it.
Some /proc
files might have a non null size because it is known in advance.
/proc/kcore
This file represents the physical memory of the system and is stored in the ELF core file for-
mat. With this pseudo-file, and an unstripped kernel (/usr/src/linux/vmlinux) binary, GDB can
be used to examine the current state of any kernel data structures.
The total length of the file is the size of physical memory (RAM) plus 4KB.
However, given the fact I haven't 128 TB of RAM on my machine, the reported value and the size that might be read do not match the documentation:
$ ls -lh /proc/kcore
-r--------. 1 root root 128T Feb 23 16:10 /proc/kcore
/proc/bus/pci/*/*
). There are a lot more of those in /sys
.
– Stéphane Chazelas
Feb 23 '16 at 14:58
proc is a virtual file system mapping file names to internal linux structures/variables; so it is normal /proc/stat having 0 bytes.
From wikipedia: procfs
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. Typically, it is mapped to a mount point named /proc at boot time. 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).
From TLDP Linux Filesystem Hierarchy: /proc
The most distinctive thing about files in this directory is the fact that all of them have a file size of 0, with the exception of kcore, mtrr and self.
Note: Actually only mtrr and self are 0 size in my servers - kcore is the memory that you are able to address, i.e. kernel virtual memory addresses hence the 128TB. Also relevant for this discussion, is /proc/kcore
not being implemented in MIPS and ARM architectures.
/proc
is a special file system. It is not something that you store files in. It is a virtual filesystem, I know it is not the right analogy but consider it something like device driver in your /dev
directory. What you write to the files in /dev
gets passed on to the system in some way. Likewise, when you read from a file, it pulls those values from the system. Hence, since there is no actual stored information in these files, the size shows as zero.