Saturday, June 13, 2015

1. Procfs
/proc file system là một loại virtual file system đặc biệt trong kernel. procfs không giống như các file system khác như Ext, NTFS, ... tồn tại thực sự trên các block device (HDD, SD, ...) , nó được tạo ra theo thời gian thực (run-time) bởi các tiến trình dưới kernel và chỉ tồn tại duy nhất trên RAM, vì thế khi tắt máy nó không hề tồn tại nữa và khi mở máy nó được tạo lại từ đầu.


procfs là interface giữa user space và kernel space, nó cung cấp thông tin về các process và system

 $cat /proc/cpuinfo  
 processor     : 0  
 vendor_id     : GenuineIntel  
 cpu family     : 6  
 model          : 42  
 model name     : Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz  
 stepping     : 7  
 microcode     : 0x29  
 cpu MHz          : 939.351  
 cache size     : 3072 KB  
 physical id     : 0  
 siblings     : 4  
 core id          : 0  
 cpu cores     : 2  
 apicid          : 0  
 initial apicid     : 0  
 fpu          : yes  
 fpu_exception     : yes  
 cpuid level     : 13  
 wp          : yes  
 ...

Tương ứng với mỗi procfs (vd: /proc/cpuinfo) sẽ có một kernel module được inplement với các API như open( ), read( ), write ( ), close( ), ... Còn rất nhiều các thông tin bạn đọc có thể xem thêm tại Wiki hoặc Linux man.





/proc/sys
Là một công cụ để thực hiện việc write cấu hình xuống kernel (ngược lại với cat /proc/cpuinfo là read) thông qua công cụ sysctl API.




VD: Cấu hình IP Foward giữa hai ethernet là eth0 & eth1:

 cat /proc/sys/net/ipv4/ip_forward    #read current configuration  
 echo 1 > /proc/sys/net/ipv4/ip_forward #enable  
 echo 0 > /proc/sys/net/ipv4/ip_forward #disable  



2. Sysfs
Sysfs là một file system tương tự như procfs, trong khi /proc cung cấp thông tin về process & system informations thì /sys lại cung cấp thông tin về devices, drivers và buses.

sys/block/ all known block devices such as hda/ ram/ sda/
sys/bus/ all registered buses. Each directory below bus/ holds by default two subdirectories:
device/ for all devices attached to that bus
driver/ for all drivers assigned with that bus.
sys/class/ for each device type there is a subdirectory: for example /printer or /sound
sys/device/ all devices known by the kernel, organised by the bus they are connected to
sys/firmware/ files in this directory handle the firmware of some hardware devices
sys/fs/ files to control a file system, currently used by FUSE, a user space file system implementation
sys/kernel/ holds directories (mount points) for other filesystems such as debugfs, securityfs.
sys/module/ each kernel module loaded is represented with a directory.
sys/power/ files to handle the power state of some hardware



Xem thêm tại people.ee.ethz.ch

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Lập trình hệ thống nhúng Linux . Powered by Luong Duy Ninh -