/proc是linux的文件系统,即proc文件系统,但它只是一个虚拟的文件系统,存在于内存中。其主要功能是显示内核(硬件)信息和进程运行信息。由于/proc将自己注册到虚拟文件系统层(VFS),所以在使用 /proc由进程pid目录、sys等子目录以及内核相关文件组成。重要的子目录:1. /proc介绍
ls -al
命令时,我们可以发现许多文件的大小都为0,但是当我们用cat more
等命令查看内容时,又会显示出文件内容。root@we:~# ls -al /proc/sys
total 0
dr-xr-xr-x 1 root root 0 Dec 19 16:16 .
dr-xr-xr-x 131 root root 0 Dec 19 16:16 ..
dr-xr-xr-x 1 root root 0 Dec 20 23:04 abi
dr-xr-xr-x 1 root root 0 Dec 20 23:04 debug
dr-xr-xr-x 1 root root 0 Dec 20 23:04 dev
dr-xr-xr-x 1 root root 0 Dec 19 16:16 fs
dr-xr-xr-x 1 root root 0 Dec 19 16:16 kernel
dr-xr-xr-x 1 root root 0 Dec 19 16:16 net
dr-xr-xr-x 1 root root 0 Dec 20 23:04 user
dr-xr-xr-x 1 root root 0 Dec 19 16:16 vm
2. /proc结构
3. /proc/sys 目录浅析
root@we:~# ls -al /proc/sys/
total 0
dr-xr-xr-x 1 root root 0 Dec 19 16:16 .
dr-xr-xr-x 131 root root 0 Dec 19 16:16 ..
dr-xr-xr-x 1 root root 0 Dec 20 23:04 abi
dr-xr-xr-x 1 root root 0 Dec 20 23:04 debug
dr-xr-xr-x 1 root root 0 Dec 20 23:04 dev
dr-xr-xr-x 1 root root 0 Dec 19 16:16 fs
dr-xr-xr-x 1 root root 0 Dec 19 16:16 kernel
dr-xr-xr-x 1 root root 0 Dec 19 16:16 net
dr-xr-xr-x 1 root root 0 Dec 20 23:04 user
dr-xr-xr-x 1 root root 0 Dec 19 16:16 vm
开启包转发:
echo 1 > /proc/sys/net/ipv4/ip_forward
开启icmp包屏蔽:
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
4. /proc/self目录浅析
root@we:~# ls -al /proc/self/
total 0
dr-xr-xr-x 9 root root 0 Dec 21 00:14 .
dr-xr-xr-x 131 root root 0 Dec 19 16:16 ..
dr-xr-xr-x 2 root root 0 Dec 21 00:14 attr
-rw-r--r-- 1 root root 0 Dec 21 00:14 autogroup
-r-------- 1 root root 0 Dec 21 00:14 auxv
-r--r--r-- 1 root root 0 Dec 21 00:14 cgroup
--w------- 1 root root 0 Dec 21 00:14 clear_refs
-r--r--r-- 1 root root 0 Dec 21 00:14 cmdline
-rw-r--r-- 1 root root 0 Dec 21 00:14 comm
-rw-r--r-- 1 root root 0 Dec 21 00:14 coredump_filter
-r--r--r-- 1 root root 0 Dec 21 00:14 cpuset
lrwxrwxrwx 1 root root 0 Dec 21 00:14 cwd -> /root
-r-------- 1 root root 0 Dec 21 00:14 environ
lrwxrwxrwx 1 root root 0 Dec 21 00:14 exe -> /bin/ls
dr-x------ 2 root root 0 Dec 21 00:14 fd
........
root@we:~# ls -al /proc/self/cmdline
-r--r--r-- 1 root root 0 Dec 21 00:24 /proc/self/cmdline
root@we:~# cat /proc/self/environ
CLUTTER_IM_MODULE=xim
root@we:~# ls -al /proc/self/fd
total 0
dr-x------ 2 root root 0 Dec 21 00:27 .
dr-xr-xr-x 9 root root 0 Dec 21 00:27 ..
lrwx------ 1 root root 64 Dec 21 00:27 0 -> /dev/pts/1
lrwx------ 1 root root 64 Dec 21 00:27 1 -> /dev/pts/1
lrwx------ 1 root root 64 Dec 21 00:27 2 -> /dev/pts/1
lr-x------ 1 root root 64 Dec 21 00:27 3 -> /proc/2542/fd
root@we:~# cat /proc/self/status
Name: cat
Umask: 0022
State: R (running)
Tgid: 2556
Ngid: 0
Pid: 2556
PPid: 1174
root@we:~# cat /proc/self/maps
5566be297000-5566be299000 r--p 00000000 08:01 131894 /bin/cat
5566be299000-5566be29e000 r-xp 00002000 08:01 131894 /bin/cat
5566be29e000-5566be2a0000 r--p 00007000 08:01 131894 /bin/cat
5566be2a1000-5566be2a2000 r--p 00009000 08:01 131894
root@we:~# cat /proc/self/statm
1042 187 171 7 0 111 0
5. /proc目录下重要的子文件
root@we:~# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.17.0-kali3-amd64 root=UUID=f1c4045c-4b33-46e3-96b7-c79a7531a831 ro initrd=/install/gtk/initrd.gz quiet
root@we:~# cat /proc/partitions
major minor #blocks name
8 0 52428800 sda
8 1 51904512 sda1
8 2 1 sda2
8 5 521216 sda5
11 0 3019904 sr0
系统上次启动以来的运行时间,如下所示,其第一个数字表示系统运行时间,第二个数字表示系统空闲时间,单位是秒;root@we:~# cat /proc/uptime
23936.88 23272.55
Comments NOTHING