Open anitsh opened 4 years ago
In a Linux system, top gets its information from a very interesting source ... "the /proc file system"
If you look at the root-directory of your system, you'll probably notice two directories ... /proc and /sys ... which upon closer inspection show themselves to be most curious. Although at first glance they appear to contain "files and directories," you soon realize that these are not "ordinary, physical files." And indeed, they are not.
The "files and directories" in these "directories" are, in fact, pure fabrications created for you by Linux itself. All kinds of information, including everything needed by a command like top, can be obtained by finding and reading these "files." When you "read from" (and sometimes, "write to") these "files and directories," the information comes from the bowels of the system itself. And you'd never know it!
So, top in Linux is not a "privileged" program at all.
It's quite a remarkable and useful concept, extremely well-implemented and very characteristic of Linux.
--- https://www.linuxquestions.org/questions/linux-general-1/how-top-command-works-630962
The examples above provide a lot of information about running processes and your system in general that can aid in debugging and troubleshooting issues.
Important per-process files:
The following are important per-process files to look for in the /proc/ filesystem: /proc/$pid/cmdline Holds the complete command line for the process /proc/$pid/cwd Symbolic link to the process' current working directory /proc/$pid/environ Contains the initial environment that was set when the program started /proc/$pid/exe Symbolic link to the path of the file that was executed /proc/$pid/fd Subdirectory for listing files that have been opened by the process /proc/$pid/io Contains I/O statistics for the process /proc/$pid/limits Displays the process resource limit /proc/$pid/maps Currently mapped memory regions and access permissions /proc/$pid/stack Trace of function calls in the process' kernel stack /proc/$pid/stat Status information about the process /proc/$pid/task/ Directory that contains thread information
Important system-wide files
Here is a list of important general files (i.e., not specific to any process):
/proc/cmdline Arguments passed to the Linux kernel during boot time
/proc/cpuinfo CPU-related information
/proc/meminfo Memory usage statistics
/proc/filesystems Listing of filesystems supported by the kernel
/proc/modules Kernel modules that are currently loaded
/proc/partitions Information about each partition on the system
/proc/swaps Information about swap space on the system
/proc/self Directory refers to the process accessing the /proc filesystem
/proc/slabinfo Information about kernel caches
/proc/sys Various files and sub-directories about kernel variables
The proc File System