Your SlideShare is downloading. ×
20070317 procfs slide
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

20070317 procfs slide

777
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
777
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Using and Programming Proc filesystem from internet ...
  • 2. Content ● What's Procfs ● Basic useness of Procfs ● Programming Procfs ● Example source code ● Conclusion
  • 3. What is Procfs ● In its simplest form procfs provides file-system abstraction for processes, presenting information about processes, their ex ecution environment, resource utilization etc. as files. ● The original design goal of procfs was to make debugger impl ementation easier. ● Systems like Linux have exposed a lot of other system interf aces and information through procfs ● There are Linux system utilities that essentially cat files in procfs!
  • 4. What is Procfs (cont.) ● It is a virtual file system – Is a special file system in the linux kernel. – It exists only in memory. – Is a virtual file system that is not associated with a block device but exists only in memory. – allows programs in the user space to access to certain info rmation from the kernel.
  • 5. What is Procfs (cont.) ● It is an abstraction allowing – access information on – configure the kernel ● It can be mounted by # mount -t proc proc /mnt Now procfs is mounted on /mnt, same to /proc
  • 6. Basic useness of Procfs ● /proc/sys are sysctl files – They do not belong to procfs – Managed by different APIs ● Number named Dirs – PID as name – Appear and disappear as processes are created, finish
  • 7. Basic useness of Procfs (cont.) ● Structure – cmdline : argument list, null-separated strings – cwd : symbolic link to the current working directory – environ : environment for the process – exe : a symbolic link containing the actual path name of the executed command – fd : a subdirectory containing one entry for each file which the process has open (file descriptor), a symbolic link to the actual file) – maps : currently mapped memory regions and their access permissions – root : points to the file system root, e.g / – stat : information about the process (used by ps) – statm : information about memory status in pages – status : much of the information in stat and statm in a more human readable/parsable format
  • 8. Basic useness of Procfs (cont.) ● /proc/self: symbolic link to the current process ● /proc/cpuinfo: a collection of CPU and system architecture depen dent items, for each supported architecture a different list ● /proc/devices: listing of major numbers and device groups ● /proc/pci: listing of all PCI devices found during kernel i nitialization and their configuration (lspci command) ● /proc/tty/driver/serial: information on serial ports ● /proc/version: information on the kernel version – /proc/sys/kernel/ostype – /proc/sys/kernel/osrelease – /proc/sys/kernel/version
  • 9. Basic useness of Procfs (cont.) ● /proc/sys/kernel/hostname: the name of the machine ● /proc/sys/kernel/domainname: the name of the domain ● /proc/meminfo: information on memory usage ● /proc/loadavg: load average numbers give information on the workload: – the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes – PID of the last process being executed ● /proc/uptime: two pieces of information on the uptime of the system (seconds), and the amount of time spent in idle process (seconds) – Same information as uptime
  • 10. Programming Procfs ● Program as kernel module ● #includeu <linux/proc_fs.h> ● struct proc_dir_entry* proc_mkdir (const char* name,struct proc_dir_entry* parent); ● struct proc_dir_entry* create_proc_entry (const char* name, mode_t mode,struct proc_dir_entry* parent); ● struct proc_dir_entry* proc_symlink (const char* name,struct proc_dir_entry* parent, const char *dest); ● void remove_proc_entry (const char *name, struct proc_dir_entry *parent);
  • 11. Programming Procfs (cont.) ● procfs works with call back functionsfor files: functions that are called when a specific file is being read or written. ● Such functions have to be initialized by setting the file_operations member in the struct proc_dir_entry* that the function create_proc_entry returned. ● For read only proc file, call create_proc_read_entry is enough.
  • 12. Programming Procfs (cont.) ● define read, write, open, release methods for your proc file see example source code. ● Original procfs can not pass data larger than 1 page. In order to pass large data, you should define a sequence method. ● Other detailed example, see the source code.
  • 13. Example source code ● kernel module frame work. ● read the source code for each method of proc fs. ● build it ● insmod into kernel ● cd /proc, see /proc/foo and /proc/foo/foo ● try read/write permission ● be root user ● try read/write permission ● rmmod the kernel module
  • 14. Conclusion ● Its candidate is sysfs. ● But Procfs is still very useful, because it is simple, and lot of legacy software need procfs.
  • 15. Thank you ! Q & A