1 / 19

The Linux /proc Filesystem

The Linux /proc Filesystem. CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree. Topics. Introduction / History Problems Addressed Layout Process Information Kernel Information Kernel Configuration Implementation Programming for /proc

Download Presentation

The Linux /proc Filesystem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree

  2. Topics • Introduction / History • Problems Addressed • Layout • Process Information • Kernel Information • Kernel Configuration • Implementation • Programming for /proc • Advantages & Disadvantages

  3. Introduction • What is /proc? • A pseudo-filesystem that acts as an interface to internal data structures in the kernel • What is it used for? • Can be used to obtain information about the system • Can be used to change certain kernel parameters at runtime.

  4. History • The idea of a Process Filesystem • Used for reporting process information only • Seen in UNIXes such as Solaris • /proc extends the concept • A similar implementation available for various flavors of BSD, including FreeBSD • /proc for Linux is the most actively developed

  5. The Problem • Modern kernel is highly complex • Linux kernel has device drivers built-in • An enormous amount of status information • Many run-time configurable parameters • How do we allow controlled access to kernel data and parameters and provide a familiar interface that programmers can easily adopt?

  6. The Solution • Create pseudo-filesystem to represent status information and configuration parameters as files • Provides a unified ‘API’ for collecting status information and configuring drivers • Control access through UNIX permissions • No new libraries needed – simple filesystem calls are all that is necessary • Quick, easy access via command line • Not version- or configuration-specific

  7. /proc Layout • Two major subdivisions • Read-only files/directories • Configurable settings in /proc/sys/ • Hierarchical Subdirectories for • Network • SCSI • IDE • Device Drivers • Etc…

  8. # ls -la /proc

  9. Process Information • Each process has a /proc directory identified by its PID - /proc/PID/ • Symlink /proc/self/ points to the process reading the file system • Allows access to • Process status • Process memory information • Links to cwd, exe, root dir • CPU and Memory Map information (2.4 only)

  10. Process Information (Example)

  11. Kernel Information

  12. Configuring the Kernel • Read-write entries in /proc/sys/ • Allow for tuning, monitoring and optimization of running kernel • Modifiable only by root • Parameters may be changed simply via ‘echo’ # cat /proc/sys/fs/file-max 4096 # echo 8192 > /proc/sys/fs/file-max # cat /proc/sys/fs/file-max 8192

  13. Configuring the Kernel (Cont’d) • Filesystem Data • Miscellaneous Binary Formats • General Kernel Parameters • Virtual Memory Subsystem • Device Specific Parameters • Remote Procedure Calls • Networking

  14. Examples

  15. Examples

  16. Implementation • Linux has virtual filesystem layer (VFS) • VFS provides an abstraction layer between user processes and filesystems • Allows for any filesystem to be used transparently in the system • Filesystems don’t have to be physical • /proc fileystem resides entirely in memory

  17. Implementation – Linux VFS

  18. Programming for /proc • Simple filesystem representation allows for easy programming • C calls uptimefp = myfopen (PROC_DIR "uptime"); fgets (line, sizeof (line), uptimefp); new.uptime = (unsigned long) (atof (strtok (line, " ")) * (unsigned long) HZ); • Web interfaces <html><body> <? if ($fp = fopen('/proc/sys/kernel/hostname','r')) { $result = trim(fgets($fp, 4096)); echo gethostbyaddr(gethostbyname($result)); } ?> </body></html> • Shell scripts – bash, PERL, etc.

  19. Advantages & Disadvantages • Advantages • Coherent, intuitive interface to the kernel • Great for tweaking and collecting status info • Easy to use and program for • Disadvantages • Certain amount of overhead, must use fs calls • Alleviated somewhat by sysctl() interface • User can possibly cause system instability

More Related