Upload
carolos-alex
View
31
Download
1
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
The Linux The Linux /proc/proc Filesystem Filesystem
CSE8343 – Fall 2001CSE8343 – Fall 2001
Group A1 – Alex MacFarlane, Group A1 – Alex MacFarlane, Garrick Williamson, Brad CrabtreeGarrick Williamson, Brad Crabtree
TopicsTopics
Introduction / HistoryIntroduction / History
Problems AddressedProblems Addressed
LayoutLayout
Process InformationProcess Information
Kernel InformationKernel Information
Kernel ConfigurationKernel Configuration
ImplementationImplementation
Programming for Programming for /proc/proc
Advantages & DisadvantagesAdvantages & Disadvantages
IntroductionIntroduction
What is What is /proc/proc??– A pseudo-filesystem that acts as an interface A pseudo-filesystem that acts as an interface
to internal data structures in the kernelto internal data structures in the kernel
What is it used for?What is it used for?– Can be used to obtain information about the Can be used to obtain information about the
systemsystem– Can be used to change certain kernel Can be used to change certain kernel
parameters at runtime.parameters at runtime.
HistoryHistory
The idea of a Process FilesystemThe idea of a Process Filesystem– Used for reporting process information onlyUsed for reporting process information only– Seen in UNIXes such as SolarisSeen in UNIXes such as Solaris
/proc/proc extends the concept extends the concept
A similar implementation available for A similar implementation available for various flavors of BSD, including FreeBSDvarious flavors of BSD, including FreeBSD
/proc/proc for Linux is the most actively for Linux is the most actively developeddeveloped
The ProblemThe Problem
Modern kernel is highly complexModern kernel is highly complex
Linux kernel has device drivers built-inLinux kernel has device drivers built-in
An enormous amount of status informationAn enormous amount of status information
Many run-time configurable parametersMany run-time configurable parameters
How do we allow controlled access to How do we allow controlled access to kernel data and parameters and provide a kernel data and parameters and provide a familiar interface that programmers can familiar interface that programmers can easily adopt?easily adopt?
The SolutionThe Solution
Create pseudo-filesystem to represent status Create pseudo-filesystem to represent status information and configuration parameters as filesinformation and configuration parameters as filesProvides a unified ‘API’ for collecting status Provides a unified ‘API’ for collecting status information and configuring driversinformation and configuring driversControl access through UNIX permissionsControl access through UNIX permissionsNo new libraries needed – simple filesystem No new libraries needed – simple filesystem calls are all that is necessarycalls are all that is necessaryQuick, easy access via command lineQuick, easy access via command lineNot version- or configuration-specificNot version- or configuration-specific
/proc/proc Layout Layout
Two major subdivisionsTwo major subdivisions– Read-only files/directoriesRead-only files/directories– Configurable settings in Configurable settings in /proc/sys//proc/sys/
Hierarchical Subdirectories forHierarchical Subdirectories for– NetworkNetwork– SCSISCSI– IDEIDE– Device DriversDevice Drivers– Etc…Etc…
# ls -la /proc# ls -la /proc
Process InformationProcess Information
Each process has a Each process has a /proc/proc directory directory identified by its PID - identified by its PID - /proc/PID//proc/PID/Symlink Symlink /proc/self//proc/self/ points to the process points to the process reading the file systemreading the file systemAllows access toAllows access to– Process statusProcess status– Process memory informationProcess memory information– Links to cwd, exe, root dirLinks to cwd, exe, root dir– CPU and Memory Map information (2.4 only)CPU and Memory Map information (2.4 only)
Process Information (Example)Process Information (Example)
Kernel InformationKernel InformationAPMAPM BusesBuses CPUsCPUs Available Available
DevicesDevicesDMA DMA ChannelsChannels
FilesystemsFilesystems Device Device DriversDrivers
Frame Buffer Frame Buffer DevicesDevices
IDE IDE SubsystemSubsystem
InterruptsInterrupts
Memory MapMemory Map I/O PortsI/O Ports ISA PnPISA PnP Kernel Core Kernel Core ImageImage
Kernel Kernel SymbolsSymbols
Kernel Kernel MessagesMessages
Load Load AveragesAverages
Kernel LocksKernel Locks MemoryMemory Loaded Loaded ModulesModules
Mounted Mounted FilesystemsFilesystems
NetworkingNetworking PartitionsPartitions RTCRTC SCSISCSI
StatisticsStatistics Swap SpaceSwap Space SysV IPCSysV IPC TTY DriversTTY Drivers UptimeUptime
Configuring the KernelConfiguring the Kernel
Read-write entries in Read-write entries in /proc/sys//proc/sys/
Allow for tuning, monitoring and optimization of Allow for tuning, monitoring and optimization of running kernelrunning kernel
Modifiable only by rootModifiable only by root
Parameters may be changed simply via ‘echo’Parameters may be changed simply via ‘echo’# cat /proc/sys/fs/file-max # cat /proc/sys/fs/file-max
4096 4096
# echo 8192 > /proc/sys/fs/file-max # echo 8192 > /proc/sys/fs/file-max
# cat /proc/sys/fs/file-max # cat /proc/sys/fs/file-max
8192 8192
Configuring the Kernel (Cont’d)Configuring the Kernel (Cont’d)
Filesystem DataFilesystem Data
Miscellaneous Binary FormatsMiscellaneous Binary Formats
General Kernel ParametersGeneral Kernel Parameters
Virtual Memory SubsystemVirtual Memory Subsystem
Device Specific ParametersDevice Specific Parameters
Remote Procedure CallsRemote Procedure Calls
NetworkingNetworking
ExamplesExamples
ExamplesExamples
ImplementationImplementation
Linux has virtual filesystem layer (VFS)Linux has virtual filesystem layer (VFS)
VFS provides an abstraction layer VFS provides an abstraction layer between user processes and filesystemsbetween user processes and filesystems
Allows for any filesystem to be used Allows for any filesystem to be used transparently in the systemtransparently in the system
Filesystems don’t have to be physicalFilesystems don’t have to be physical
/proc/proc fileystem resides entirely in memory fileystem resides entirely in memory
Implementation – Linux VFSImplementation – Linux VFS
Programming for Programming for /proc/proc
Simple filesystem representation allows for Simple filesystem representation allows for easy programmingeasy programmingC callsC callsuptimefp = myfopen (PROC_DIR "uptime");uptimefp = myfopen (PROC_DIR "uptime");fgets (line, sizeof (line), uptimefp);fgets (line, sizeof (line), uptimefp);new.uptime = new.uptime =
(unsigned long) (atof (strtok (line, " ")) * (unsigned long) (unsigned long) (atof (strtok (line, " ")) * (unsigned long) HZ);HZ);
Web interfacesWeb interfaces<html><body><html><body><? if ($fp = fopen('/proc/sys/kernel/hostname','r')) {<? if ($fp = fopen('/proc/sys/kernel/hostname','r')) {
$result = trim(fgets($fp, 4096));$result = trim(fgets($fp, 4096));echo gethostbyaddr(gethostbyname($result)); } ?>echo gethostbyaddr(gethostbyname($result)); } ?>
</body></html></body></html>
Shell scripts – bash, PERL, etc.Shell scripts – bash, PERL, etc.
Advantages & DisadvantagesAdvantages & Disadvantages
AdvantagesAdvantages– Coherent, intuitive interface to the kernelCoherent, intuitive interface to the kernel– Great for tweaking and collecting status infoGreat for tweaking and collecting status info– Easy to use and program forEasy to use and program for
DisadvantagesDisadvantages– Certain amount of overhead, must use fs callsCertain amount of overhead, must use fs calls
Alleviated somewhat by sysctl() interfaceAlleviated somewhat by sysctl() interface
– User can possibly cause system instabilityUser can possibly cause system instability