The linux proc filesystem
This presentation is the property of its rightful owner.
Sponsored Links
1 / 19

The Linux /proc Filesystem PowerPoint PPT Presentation


  • 96 Views
  • Uploaded on
  • Presentation posted in: General

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.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…


Ls la proc

# ls -la /proc


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)


Process information example

Process Information (Example)


Kernel information

Kernel Information


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


Examples

Examples


Examples1

Examples


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


Implementation linux vfs

Implementation – Linux VFS


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


  • Login