the linux /proc filesystem cse8343 – fall 2001 group a1 – alex macfarlane, garrick williamson,...
TRANSCRIPT
![Page 1: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/1.jpg)
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
![Page 2: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/2.jpg)
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
![Page 3: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/3.jpg)
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.
![Page 4: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/4.jpg)
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
![Page 5: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/5.jpg)
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?
![Page 6: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/6.jpg)
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
![Page 7: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/7.jpg)
/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…
![Page 8: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/8.jpg)
# ls -la /proc# ls -la /proc
![Page 9: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/9.jpg)
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)
![Page 10: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/10.jpg)
Process Information (Example)Process Information (Example)
![Page 11: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/11.jpg)
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
![Page 12: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/12.jpg)
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
![Page 13: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/13.jpg)
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
![Page 14: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/14.jpg)
ExamplesExamples
![Page 15: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/15.jpg)
ExamplesExamples
![Page 16: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/16.jpg)
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
![Page 17: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/17.jpg)
Implementation – Linux VFSImplementation – Linux VFS
![Page 18: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/18.jpg)
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.
![Page 19: The Linux /proc Filesystem CSE8343 – Fall 2001 Group A1 – Alex MacFarlane, Garrick Williamson, Brad Crabtree](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ea25503460f94ba5ab8/html5/thumbnails/19.jpg)
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