the linux proc filesystem
Download
Skip this Video
Download Presentation
The Linux /proc Filesystem

Loading in 2 Seconds...

play fullscreen
1 / 19

The Linux /proc Filesystem - PowerPoint PPT Presentation


  • 143 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' The Linux /proc Filesystem' - carolos-alex


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
the linux proc filesystem

The Linux /proc Filesystem

CSE8343 – Fall 2001

Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree

topics
Topics
  • Introduction / History
  • Problems Addressed
  • Layout
  • Process Information
  • Kernel Information
  • Kernel Configuration
  • Implementation
  • Programming for /proc
  • Advantages & Disadvantages
introduction
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.
history
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
the problem
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?
the solution
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
proc layout
/proc Layout
  • Two major subdivisions
    • Read-only files/directories
    • Configurable settings in /proc/sys/
  • Hierarchical Subdirectories for
    • Network
    • SCSI
    • IDE
    • Device Drivers
    • Etc…
process information
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)
configuring the kernel
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

configuring the kernel cont d
Configuring the Kernel (Cont’d)
  • Filesystem Data
  • Miscellaneous Binary Formats
  • General Kernel Parameters
  • Virtual Memory Subsystem
  • Device Specific Parameters
  • Remote Procedure Calls
  • Networking
implementation
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
programming for proc
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.
advantages disadvantages
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
ad