文件类型
当我们使用命令查看linux目录下的内容时,如下:
[root@optimize ~]# ll
total 4
-rw-------. 1 root root 1246 Jun 11 10:54 anaconda-ks.cfg
左侧第一个字符代表的就是文件类型
-:普通文件(可执行、图片、文本) REG
d:目录
l:链接
b:块设备- 硬盘
c:字符设备- 键盘 CHR
s:socket
p:pipeline
[eventpoll]:
…
示例:
[root@optimize opt]# ll
total 21428
-rw-r--r-- 1 root root 3642862 Jun 23 11:02 11683.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
如上图所示,11683.log是一个普通文件,apache-tomcat-8.0.53是一个目录
[root@optimize opt]# cd /dev/
[root@optimize dev]# ll
total 0
crw-rw---- 1 root video 10, 175 Jun 28 00:44 agpgart
crw------- 1 root root 10, 235 Jun 28 00:44 autofs
lrwxrwxrwx 1 root root 3 Jun 28 00:44 cdrom -> sr0
drwxr-xr-x 6 root root 120 Jun 28 00:44 disk
brw-rw---- 1 root disk 253, 0 Jun 28 00:44 dm-0
brw-rw---- 1 root disk 253, 1 Jun 28 00:44 dm-1
drwxr-xr-x 2 root root 0 Jun 28 00:44 hugepages
srw-rw-rw- 1 root root 0 Jun 28 00:44 log
brw-rw---- 1 root disk 8, 0 Jun 28 00:44 sda
brw-rw---- 1 root disk 8, 1 Jun 28 00:44 sda1
brw-rw---- 1 root disk 8, 2 Jun 28 00:44 sda2
crw-rw---- 1 root disk 21, 0 Jun 28 00:44 sg0
crw-rw---- 1 root cdrom 21, 1 Jun 28 00:44 sg1
drwxrwxrwt 2 root root 40 Jun 28 00:44 shm
crw------- 1 root root 10, 231 Jun 28 00:44 snapshot
drwxr-xr-x 3 root root 200 Jun 28 00:44 snd
brw-rw---- 1 root cdrom 11, 0 Jun 28 00:44 sr0
lrwxrwxrwx 1 root root 15 Jun 28 00:44 stderr -> /proc/self/fd/2
crw-rw-rw- 1 root tty 5, 0 Jun 28 00:44 tty
如上所示:对实际显示的内容进行了删减,sda代表一块硬盘,类型为b,是块设备;像我们的终端tty,就是一个字符设备,类型为c;
[root@optimize opt]# ll
total 21428
-rw-r--r-- 1 root root 3642862 Jun 23 11:02 11683.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
[root@optimize opt]# ln 11683.log 11684.log
[root@optimize opt]# ll
total 24988
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11683.log
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11684.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
[root@optimize opt]# stat 11683.log
File: ‘11683.log’
Size: 3642862 Blocks: 7120 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 879676 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-06-23 11:02:21.861608273 -0400
Modify: 2020-06-23 11:02:07.665576387 -0400
Change: 2020-06-28 07:29:17.096904730 -0400
Birth: -
[root@optimize opt]# stat 11684.log
File: ‘11684.log’
Size: 3642862 Blocks: 7120 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 879676 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-06-23 11:02:21.861608273 -0400
Modify: 2020-06-23 11:02:07.665576387 -0400
Change: 2020-06-28 07:29:17.096904730 -0400
Birth: -
做完以上操作后,我们发现11683.log和11684.log的Inode id是一样的,证明这是一个硬链接,下面我们再做一个软连接进行对比
[root@optimize opt]# ln -s 11683.log 11685.log
[root@optimize opt]# stat 11683.log
File: ‘11683.log’
Size: 3642862 Blocks: 7120 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 879676 Links: 2
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-06-23 11:02:21.861608273 -0400
Modify: 2020-06-23 11:02:07.665576387 -0400
Change: 2020-06-28 07:29:17.096904730 -0400
Birth: -
[root@optimize opt]# stat 11685.log
File: ‘11685.log’ -> ‘11683.log’
Size: 9 Blocks: 0 IO Block: 4096 symbolic link
Device: fd00h/64768d Inode: 889760 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-06-28 07:32:00.583214231 -0400
Modify: 2020-06-28 07:32:00.583214231 -0400
Change: 2020-06-28 07:32:00.583214231 -0400
Birth: -
经过与硬链接对比,我们发现软连接的两个文件的Inode id是不一样的
所谓硬链接:两个变量名指向同一个物理文件,修改一个文件,另一个文件也会随之变动
[root@optimize opt]# ll
total 24988
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11683.log
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11684.log
lrwxrwxrwx 1 root root 9 Jun 28 07:32 11685.log -> 11683.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
[root@optimize opt]# rm -rf 11684.log
[root@optimize opt]# ll
total 21428
-rw-r--r-- 1 root root 3642862 Jun 23 11:02 11683.log
lrwxrwxrwx 1 root root 9 Jun 28 07:32 11685.log -> 11683.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
当我们删除刚才创建的硬链接文件后,发现原来的11683.log还在,只是引用的数由2变成了1,root前面的那个数
区别:软连接删除原文件后,软连接指向的文件会爆红显示不存在,而硬链接则不受影响
我们准备一个干净的目录做下面的测试
[root@optimize opt]# mkdir itliu
[root@optimize opt]# ll
total 24988
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11683.log
-rw-r--r-- 2 root root 3642862 Jun 23 11:02 11684.log
lrwxrwxrwx 1 root root 9 Jun 28 07:32 11685.log -> 11683.log
drwxr-xr-x 9 root root 160 Nov 27 2018 apache-tomcat-8.0.53
drwxr-xr-x 2 root root 6 Jun 28 07:43 itliu
[root@optimize opt]# cd itliu
[root@optimize itliu]# ls
[root@optimize itliu]# dd if=/dev/zero of=mydisk.img bs=1048576 count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.37027 s, 283 MB/s
[root@optimize itliu]# ll
total 102400
-rw-r--r-- 1 root root 104857600 Jun 28 07:43 mydisk.img
[root@optimize itliu]# ll -h
total 100M
-rw-r--r-- 1 root root 100M Jun 28 07:43 mydisk.img
if -> inputfile
of -> outputfile
bs -> blocksize块大小 1048576 -> 1M
count -> 有多少个bs,100个1M大小的bs,也就是说创建的mydisk.img是100M
dd命令参考 https://www.runoob.com/linux/linux-comm-dd.html
创建mydisk.img的目的是把这个文件当做一个磁盘挂载到我们的文件系统中去
[root@optimize itliu]# losetup /dev/loop0 mydisk.img
[root@optimize itliu]# mke2fs /dev/loop0
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
使用 losetup将磁盘镜像文件虚拟成块设备并格式化成ext2文件系统
losetup -> https://www.runoob.com/linux/linux-comm-losetup.html
mke2fs -> https://www.runoob.com/linux/linux-comm-mke2fs.html
挂载块设备
[root@optimize itliu]# cd /mnt/
[root@optimize mnt]# ls
[root@optimize mnt]# mkdir tmp
[root@optimize mnt]# mount -t ext2 /dev/loop0 /mnt/tmp/
[root@optimize mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 17811456 2033304 15778152 12% /
devtmpfs 1001892 0 1001892 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 9720 1004336 1% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 135596 902740 14% /boot
tmpfs 202812 0 202812 0% /run/user/0
/dev/loop0 99150 1550 92480 2% /mnt/tmp
挂载后我们的虚拟文件目录下面多了/mnt/tmp,我们访问这个目录也就相当于访问了我们的/dev/loop0块设备
进入到我们的虚拟目录/mnt/tmp中,现在是空的
[root@optimize mnt]# cd tmp/
[root@optimize tmp]# ls
lost+found
查看我们的解释程序在哪
[root@optimize tmp]# whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
创建我们自己的bin目录,用来放bash解释程序,lib64用来放bash关联的动态链接库,ldd用来查看bash关联的动态链接库
[root@optimize tmp]# mkdir bin lib64
[root@optimize tmp]# ldd /usr/bin/bash
linux-vdso.so.1 => (0x00007ffd2efef000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fb05b2f4000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fb05b0f0000)
libc.so.6 => /lib64/libc.so.6 (0x00007fb05ad23000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb05b51e000)
将bash解释程序copy至当前目录下的bin目录,将bash需要的动态链接库copy至lib64目录
[root@optimize tmp]# cp /usr/bin/bash ./bin/
[root@optimize tmp]# cp /lib64/{libtinfo.so.5,libdl.so.2,libc.so.6,ld-linux-x86-64.so.2} ./lib64/
将当前目录变更为根目录并打印进程号
[root@optimize tmp]# chroot ./
bash-4.2# echo $$
19915
写入字符串到跟目录下的文件abc.txt,退出到之前的根目录,发现并没有abc.txt,abc.txt存在于刚才chroot后的根目录
bash-4.2# echo "aaa" -> /abc.txt
bash-4.2# exit
exit
[root@optimize tmp]# ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@optimize tmp]# cd /mnt/tmp/
[root@optimize tmp]# ls
abc.txt bin lib64 lost+found
[root@optimize tmp]# echo $$
19763
下面演示当前进程打开了那些文件,使用lsof命令
lsof命令传送门
[root@optimize tmp]# lsof -p $$
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 19763 root cwd DIR 7,0 1024 2 /mnt/tmp
bash 19763 root rtd DIR 253,0 224 64 /
bash 19763 root txt REG 253,0 964608 50333656 /usr/bin/bash
bash 19763 root mem REG 253,0 106075056 50566106 /usr/lib/locale/locale-archive
bash 19763 root mem REG 253,0 61624 42280 /usr/lib64/libnss_files-2.17.so
bash 19763 root mem REG 253,0 2151672 42262 /usr/lib64/libc-2.17.so
bash 19763 root mem REG 253,0 19288 42268 /usr/lib64/libdl-2.17.so
bash 19763 root mem REG 253,0 174576 73357 /usr/lib64/libtinfo.so.5.9
bash 19763 root mem REG 253,0 163400 42255 /usr/lib64/ld-2.17.so
bash 19763 root mem REG 253,0 26254 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 19763 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 255u CHR 136,0 0t0 3 /dev/pts/0
上述命令显示的REG就对应之前所说的文件类型为-的普通文件,CHR对应文件类型为c的字符设备
FD -> 文件描述符
TYPE -> 文件类型
DEVICE -> 哪一个设备号的哪一块
SIZE/OFF -> 偏移量
创建文件描述符8 ,输入来自于文件ooxx.txt
[root@optimize /]# exec 8< ooxx.txt
[root@optimize /]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 19763 root cwd DIR 253,0 64 /
bash 19763 root rtd DIR 253,0 64 /
bash 19763 root txt REG 253,0 50333656 /usr/bin/bash
bash 19763 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 19763 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 19763 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 19763 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 19763 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 19763 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 19763 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 19763 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 8r REG 253,0 0t0 889779 /ooxx.txt
bash 19763 root 255u CHR 136,0 0t0 3 /dev/pts/0
注意:文件描述符8后面跟的是r,代表只读,而u代表读写都可以,并且这个文件刚打开,偏移量为0
从标准输入中读取信息到变量a,标准输入的信息来自于文件描述符8
查看到文件描述8的偏移量到了4,刚才读了字符aaa,加上一个换行符,正好偏移量到了4,并且变量a的内容也是文件ooxx.txt的第一行内容,read命令遇到换行符就停止
[root@optimize /]# read a 0<& 8
[root@optimize /]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 19763 root cwd DIR 253,0 64 /
bash 19763 root rtd DIR 253,0 64 /
bash 19763 root txt REG 253,0 50333656 /usr/bin/bash
bash 19763 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 19763 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 19763 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 19763 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 19763 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 19763 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 19763 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 19763 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 8r REG 253,0 0t4 889779 /ooxx.txt
bash 19763 root 255u CHR 136,0 0t0 3 /dev/pts/0
[root@optimize /]# echo $a
aaa
我们再打开一个窗口,查看新窗口的进程id号,同样也创建一个文件描述符6,让它的输入也来自文件ooxx.txt,查看进程打开的文件,观察文件描述符6的偏移量,发现是0;
[root@optimize ~]# exec 6< /ooxx.txt
[root@optimize ~]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 19989 root cwd DIR 253,0 33574977 /root
bash 19989 root rtd DIR 253,0 64 /
bash 19989 root txt REG 253,0 50333656 /usr/bin/bash
bash 19989 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 19989 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 19989 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 19989 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 19989 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 19989 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 19989 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 19989 root 0u CHR 136,1 0t0 4 /dev/pts/1
bash 19989 root 1u CHR 136,1 0t0 4 /dev/pts/1
bash 19989 root 2u CHR 136,1 0t0 4 /dev/pts/1
bash 19989 root 6r REG 253,0 0t0 889779 /ooxx.txt
bash 19989 root 255u CHR 136,1 0t0 4 /dev/pts/1
以上两个操作证明了:两个程序可以打开一个文件,但是每个程序维护了自己的那个指针,但是文件是同一个文件
创建一个文件描述符9,来自文件描述9的信息都输出到文件xxoo.txt
[root@optimize /]# exec 9> bula.txt
[root@optimize /]# ll /proc/$$/fd
total 0
lrwx------ 1 root root 64 Jun 28 07:14 0 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 28 07:14 1 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 28 07:14 2 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 28 08:30 255 -> /dev/pts/0
lr-x------ 1 root root 64 Jun 28 08:57 8 -> /ooxx.txt
l-wx------ 1 root root 64 Jun 28 09:34 9 -> /bula.txt
[root@optimize /]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 19763 root cwd DIR 253,0 64 /
bash 19763 root rtd DIR 253,0 64 /
bash 19763 root txt REG 253,0 50333656 /usr/bin/bash
bash 19763 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 19763 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 19763 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 19763 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 19763 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 19763 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 19763 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 19763 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 19763 root 8r REG 253,0 0t4 889779 /ooxx.txt
bash 19763 root 9w REG 253,0 0t0 889763 /bula.txt
bash 19763 root 255u CHR 136,0 0t0 3 /dev/pts/0
查看当前脏页为0
[root@optimize /]# cat /proc/vmstat | grep dirty
nr_dirty 0
nr_dirty_threshold 129585
nr_dirty_background_threshold 43195
写入信息到文件描述符9后再次查看脏页为1,并且查看脏页的刷新策略
[root@optimize /]# echo "aagfagasgagafadsgagagvagadagasdgagadgadgagagaga" >& 9
[root@optimize /]# cat /proc/vmstat | grep dirty
nr_dirty 1
nr_dirty_threshold 129601
nr_dirty_background_threshold 43200
[root@optimize bin]# sysctl -a | grep dirty
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.ens33.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.dirty_background_bytes = 0
vm.dirty_background_ratio = 10
vm.dirty_bytes = 0
vm.dirty_expire_centisecs = 3000
vm.dirty_ratio = 30
vm.dirty_writeback_centisecs = 500
打开一个新的窗口进行演示
socket和pipeline文件类型的演示,文件描述符8代表的就是一个socket
[root@optimize ~]# exec 8<> /dev/tcp/www.baidu.com/80
[root@optimize ~]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 20587 root cwd DIR 253,0 33574977 /root
bash 20587 root rtd DIR 253,0 64 /
bash 20587 root txt REG 253,0 50333656 /usr/bin/bash
bash 20587 root mem REG 253,0 42290 /usr/lib64/libresolv-2.17.so
bash 20587 root mem REG 253,0 42278 /usr/lib64/libnss_dns-2.17.so
bash 20587 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 20587 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 20587 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 20587 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 20587 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 20587 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 20587 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 20587 root 0u CHR 136,1 0t0 4 /dev/pts/1
bash 20587 root 1u CHR 136,1 0t0 4 /dev/pts/1
bash 20587 root 2u CHR 136,1 0t0 4 /dev/pts/1
bash 20587 root 8u IPv4 57270 0t0 TCP optimize:35482->103.235.46.39:http (ESTABLISHED)
bash 20587 root 255u CHR 136,1 0t0 4 /dev/pts/1
pipeline可用管道进行演示
[root@optimize ~]# { echo $BASHPID ; read x; } | { cat ; echo $BASHPID ; read y; }
55235
使用两个管道,第二个管道接收第一个管道的输出
由输出可见第一个管道是起了一个子进程,且进程号为55235,我们根据55235找到它的父进程从而找到右边管道的子进程id
[root@optimize ~]# ps -ef|grep 55235
root 55235 55210 0 07:02 pts/0 00:00:00 -bash
root 55313 55251 0 07:03 pts/1 00:00:00 grep --color=auto 55235
[root@optimize ~]# ps -ef|grep 55210
root 55210 55208 0 07:02 pts/0 00:00:00 -bash
root 55235 55210 0 07:02 pts/0 00:00:00 -bash
root 55236 55210 0 07:02 pts/0 00:00:00 -bash
root 55325 55251 0 07:04 pts/1 00:00:00 grep --color=auto 55210
根据55235找到父进程55210,然后根据55210找到两个子进程55235和55236,很明显55235就是左边管道的进程id,55236就是右边管道的子进程id
通过lsof -op pid 查看进程打开的文件描述符
[root@optimize ~]# lsof -op 55235
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 55235 root cwd DIR 253,0 33574977 /root
bash 55235 root rtd DIR 253,0 64 /
bash 55235 root txt REG 253,0 50333656 /usr/bin/bash
bash 55235 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 55235 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 55235 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 55235 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 55235 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 55235 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 55235 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 55235 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 55235 root 1w FIFO 0,9 0t0 87907 pipe
bash 55235 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 55235 root 255u CHR 136,0 0t0 3 /dev/pts/0
[root@optimize ~]# lsof -op 55236
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 55236 root cwd DIR 253,0 33574977 /root
bash 55236 root rtd DIR 253,0 64 /
bash 55236 root txt REG 253,0 50333656 /usr/bin/bash
bash 55236 root mem REG 253,0 50566106 /usr/lib/locale/locale-archive
bash 55236 root mem REG 253,0 42280 /usr/lib64/libnss_files-2.17.so
bash 55236 root mem REG 253,0 42262 /usr/lib64/libc-2.17.so
bash 55236 root mem REG 253,0 42268 /usr/lib64/libdl-2.17.so
bash 55236 root mem REG 253,0 73357 /usr/lib64/libtinfo.so.5.9
bash 55236 root mem REG 253,0 42255 /usr/lib64/ld-2.17.so
bash 55236 root mem REG 253,0 33726611 /usr/lib64/gconv/gconv-modules.cache
bash 55236 root 0r FIFO 0,9 0t0 87907 pipe
bash 55236 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 55236 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 55236 root 255u CHR 136,0 0t0 3 /dev/pts/0
可以看到55236的87907 pipe标准输入在等待55235的87907 pipe的标准输出