第一个进程
[root@LinuxOparation ~]# cd /proc/$$/fd
[root@LinuxOparation fd]# pwd
/proc/32629/fd
[root@LinuxOparation fd]# exec 8< /root/newDir/newfile.txt
[root@LinuxOparation fd]# read firstline <& 8
[root@LinuxOparation fd]# echo $firstline
aa
[root@LinuxOparation fd]# read firstline <& 8
[root@LinuxOparation fd]# read firstline <& 8
[root@LinuxOparation fd]# echo $firstline
dasda
[root@LinuxOparation fd]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 32629 root cwd DIR 0,3 2216432 /proc/32629/fd
bash 32629 root rtd DIR 253,1 2 /
bash 32629 root txt REG 253,1 657640 /usr/bin/bash
bash 32629 root mem REG 253,1 666054 /usr/lib/locale/locale-archive
bash 32629 root mem REG 253,1 663465 /usr/lib64/libnss_files-2.17.so
bash 32629 root mem REG 253,1 657568 /usr/lib64/libc-2.17.so
bash 32629 root mem REG 253,1 663461 /usr/lib64/libdl-2.17.so
bash 32629 root mem REG 253,1 657639 /usr/lib64/libtinfo.so.5.9
bash 32629 root mem REG 253,1 657554 /usr/lib64/ld-2.17.so
bash 32629 root mem REG 253,1 787497 /usr/lib64/gconv/gconv-modules.cache
bash 32629 root 0u CHR 136,1 0t0 4 /dev/pts/1
bash 32629 root 1u CHR 136,1 0t0 4 /dev/pts/1
bash 32629 root 2u CHR 136,1 0t0 4 /dev/pts/1
bash 32629 root 8r REG 253,1 0t18 137823 /root/newDir/newfile.txt
bash 32629 root 255u CHR 136,1 0t0 4 /dev/pts/1
第二个进程
[root@LinuxOparation fd]# exec 6< /root/newDir/newfile.txt
[root@LinuxOparation fd]# lsof -op $$
[root@LinuxOparation fd]# read a <& 6
[root@LinuxOparation fd]# echo $a
aa
[root@LinuxOparation fd]# lsof -op $$
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
bash 32479 root cwd DIR 0,3 2214612 /proc/32479/fd
bash 32479 root rtd DIR 253,1 2 /
bash 32479 root txt REG 253,1 657640 /usr/bin/bash
bash 32479 root mem REG 253,1 666054 /usr/lib/locale/locale-archive
bash 32479 root mem REG 253,1 663465 /usr/lib64/libnss_files-2.17.so
bash 32479 root mem REG 253,1 657568 /usr/lib64/libc-2.17.so
bash 32479 root mem REG 253,1 663461 /usr/lib64/libdl-2.17.so
bash 32479 root mem REG 253,1 657639 /usr/lib64/libtinfo.so.5.9
bash 32479 root mem REG 253,1 657554 /usr/lib64/ld-2.17.so
bash 32479 root mem REG 253,1 787497 /usr/lib64/gconv/gconv-modules.cache
bash 32479 root 0u CHR 136,0 0t0 3 /dev/pts/0
bash 32479 root 1u CHR 136,0 0t0 3 /dev/pts/0
bash 32479 root 2u CHR 136,0 0t0 3 /dev/pts/0
bash 32479 root 6r REG 253,1 0t3 137823 /root/newDir/newfile.txt
bash 32479 root 255u CHR 136,0 0t0 3 /dev/pts/0
可以看到两个进程读取/root/newDir/newfile.txt文件的偏移量都不一致。
网友评论