[20171101]linux peekfd的简单使用.txt

[20171101]linux peekfd的简单使用.txt
--//今天再解决一个问题时需要使用fuser命令,看看某个文件是那些进程打开,在执行时发现普通用户无法执行,我记忆里普通用户可以执
--//行的,我看了一台CentOS release 6.2 (Final)的机器,可以正常执行,我还发现在这台机器的/etc/peofile路径中包含如下脚本:

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi

--//我使用另外一台Oracle Linux Server release 5.9机器:
# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
fi

--//而fuser路径实际上是
# which fuser
/sbin/fuser

--//而无意中我发现centos 6.2的机器中还包含一个peekfd命令.

#  rpm -qilf `which fuser`
Name        : psmisc                       Relocations: (not relocatable)
Version     : 22.6                              Vendor: CentOS
Release     : 15.el6_0.1                    Build Date: Sat 25 Jun 2011 02:02:12 PM CST
Install Date: Tue 03 Jul 2012 12:11:22 PM CST      Build Host: c6b5.bsys.dev.centos.org
Group       : Applications/System           Source RPM: psmisc-22.6-15.el6_0.1.src.rpm
Size        : 222302                           License: GPLv2+
Signature   : RSA/8, Wed 06 Jul 2011 09:45:24 AM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://sourceforge.net/projects/psmisc
Summary     : Utilities for managing processes on your system
Description :
The psmisc package contains utilities for managing processes on your
system: pstree, killall and fuser.  The pstree command displays a tree
structure of all of the running processes on your system.  The killall
command sends a specified signal (SIGTERM if nothing is specified) to
processes identified by name.  The fuser command identifies the PIDs
of processes that are using specified files or filesystems.
/sbin/fuser
/usr/bin/killall
/usr/bin/peekfd
/usr/bin/pstree
/usr/bin/pstree.x11
/usr/share/doc/psmisc-22.6
/usr/share/doc/psmisc-22.6/AUTHORS
/usr/share/doc/psmisc-22.6/COPYING
/usr/share/doc/psmisc-22.6/INSTALL
/usr/share/doc/psmisc-22.6/README
...

--//而Oracle Linux Server release 5.9的机器没有:
# rpm -qilf $(which fuser )
Name        : psmisc                       Relocations: (not relocatable)
Version     : 22.2                              Vendor: Oracle America
Release     : 11                            Build Date: Wed 09 Jan 2013 03:29:45 PM CST
Install Date: Fri 29 Aug 2014 09:28:53 PM CST      Build Host: ca-build56.us.oracle.com
Group       : Applications/System           Source RPM: psmisc-22.2-11.src.rpm
Size        : 162941                           License: BSD/GPL
Signature   : DSA/SHA1, Fri 11 Jan 2013 05:08:40 AM CST, Key ID 66ced3de1e5e0159
URL         : http://psmisc.sourceforge.net
Summary     : Utilities for managing processes on your system.
Description :
The psmisc package contains utilities for managing processes on your
system: pstree, killall and fuser.  The pstree command displays a tree
structure of all of the running processes on your system.  The killall
command sends a specified signal (SIGTERM if nothing is specified) to
processes identified by name.  The fuser command identifies the PIDs
of processes that are using specified files or filesystems.
/sbin/fuser
/usr/bin/killall
/usr/bin/pstree
/usr/bin/pstree.x11
/usr/share/locale/bg/LC_MESSAGES/psmisc.mo

--//好奇心决定学习一下peekfd命令. peek 偷看, 窥视的意思,fd 应该表示file descriptors.
#  man peekfd
PEEKFD(1)                        User Commands                       PEEKFD(1)

NAME
       peekfd - peek at file descriptors of running processes

SYNOPSIS
       peekfd [-8,--eight-bit-clean] [-n,--no-headers] [-f,--follow] [-d,--duplicates-removed] [-V,--version] [-h,--help] pid [fd] [fd] ...

DESCRIPTION
       peekfd attaches to a running process and intercepts all reads and writes to file descriptors.  You can specify
       the desired file descriptor numbers or dump all of them.

OPTIONS
       -8     Do no post-processing on the bytes being read or written.
       -n     Do not display headers indicating the source of the bytes dumped.
       -c     Also dump the requested file descriptor activity in any new child processes that are created.
       -d     Remove duplicate read/writes from the output.  If you're looking at a tty with echo, you might want this.
       -v     Display a version string.
       -h     Display a help message.

--//通过这个命令简单了解打开文件句柄的读写情况.简单测试一下:
--//我不想在生产系统做这些测试,我直接把/usr/bin/peekfd拷贝到我自己的测试环境.我觉得应该没有问题.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> @ &r/spid

       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
       274         11 5019        21          6 alter system kill session '274,11' immediate;

2.测试:
--//session 1:
# peekfd 5019

--//session 2:
SCOTT@book> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

--//session 1:
# peekfd 5019

writing fd 10:
[02]  [10]  [06]  [10]  [17]  [0e] 絆 [12]  [9a] 瞅狈 [97]  [94] 0鹃 [8e] 謝u [0b]  [01]  [10]  [10]  1 [03] Q [01]  [02]  [02]  [16]  [06]  [06]  [06] DEPTNO [01]  [01]  [80]  [0e] T [03]  [01]  [0e]  [01]  [05]  [05]  [05] DNAME [01]  [01]  [01]  [80]
T [03]  [01]
[01]  [03]  [03]  [03] LOC [02]  [07]  [07] xu [0b]  [01]  [10]  [10]   [01] ?[1f]

[06]  [01]  [1a]  [03]  [01]  [07]  [1a] , [01]  [03]  [02] ?[0b]
ACCOUNTING [08] NEW YORK [08]  [06]
V^ [17]  [03]  [05]  [04]  [01]  [1c]  [01]  [01]  [05]  [0e]  [03]   [1e]  [01] 6 [01] @?[0e]  [0c]  [01] & [06]  [06]  [01]  [1a]  [03] ?[07]  [16] , [01]  [03]  [02] ?[15]  [08] RESEARCH [06] DALLAS [07]  [14] , [01]  [03]  [02] ?[1f]  [05] SALES [07] CHICAGO [07]  [18] , [01]  [03]  [02] ?
OPERATIONS [06] BOSTON [04]  [01]  [1d]  [01]  [04] { [05]  [05]  [03]   [1f]  [01] 6 [01] @?[0e]  [0c]  [19] ORA-01403: no data found

--//有点乱,很明显显示的以上输出的信息.

# ls -l /proc/5019/fd/10
l-wx------ 1 oracle oinstall 64 2017-11-01 15:17:37 /proc/5019/fd/10 -> pipe:[35968225]

--//继续测试:
SCOTT@book> alter system flush BUFFER_CACHE;
System altered.

SCOTT@book> select * from dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

writing fd 8:
<msg time="2017-11-01T15:19:39.091+08:00" org_id="oracle" comp_id="rdbms" client_id='' type='UNKNOWN' level='16'
host_id='gxqyydg4' host_addr='192.168.100.78' module='SQL*Plus'
pid='5134'>
ALTER SYSTEM: Flushing buffer cache

Wed Nov 01 15:19:39 2017
ALTER SYSTEM: Flushing buffer cache

writing fd 10:
?[06]  [08]  [06]  [10] W^ [17]  [03]  [02]  [04]  [01]  [1c]  [01]  [02] 1 [1e]  [01] 6 [01] @?[0e]  [0c]  [02]  [10]  [06]  [10]  [17]  [0e] 絆 [12]  [9a] 瞅狈 [97]  [94] 0??[8e] 謝u [0b]  [01]  [10]  [10]  1 [03] Q [01]  [02]  [02]  [16]  [06]  [06]  [06] DEPTNO [01]  [01]  [80]  [0e] T [03]  [01]  [0e]  [01]  [05]  [05]  [05] DNAME [01]  [01]  [01]  [80]
T [03]  [01]
[01]  [03]  [03]  [03] LOC [02]  [07]  [07] xu [0b]  [01]  [10]  [15]  [06]  [01] ?[1f]

[06]  [01]  [1a]  [03]  [01]  [07]  [1a] , [01]  [03]  [02] ?[0b]
ACCOUNTING [08] NEW YORK [08]  [06] -W^ [17]  [03]  [03]  [04]  [01]  [1e]  [01]  [01]  [03]  [03]    [01] 6 [01] @?[0e]  [0c]  [01] & [06]  [06]  [01]  [1a]  [10]  [03] ?[02]  [01]  [07]  [16] , [01]  [03]  [02] ?[15]  [08] RESEARCH [06] DALLAS [07]  [14] , [01]  [03]  [02] ?[1f]  [05] SALES [07] CHICAGO [07]  [18] , [01]  [03]  [02] ?
OPERATIONS [06] BOSTON [04]  [01]  [1f]  [01]  [04] { [05]  [03]  [03]  ! [01] 6 [01] @?[0e]  [0c]  [19] ORA-01403: no data found

--//没有看到对表空间数据文件user01.dbf的读写,因为我使用内存盘,不存在对该文件的读写.而且操作系统也缓存了该文件.

# cachestats /mnt/ramdisk/book/users01.dbf
/mnt/ramdisk/book/users01.dbf            pages in cache: 32770/32770 (100.0%)  [filesize=131080.0K, pagesize=4K]

# cachedel /mnt/ramdisk/book/users01.dbf
# cachestats /mnt/ramdisk/book/users01.dbf
/mnt/ramdisk/book/users01.dbf            pages in cache: 32770/32770 (100.0%)  [filesize=131080.0K, pagesize=4K]

--//可以发现即使使用cacheldel 清除该/mnt/ramdisk/book/users01.dbf文件环境,os依旧缓存该文件.

3.重新测试:
--//关闭数据库将改文件移动到本地磁盘,然后做一个链接欺骗oracle还在原来位置.

$ mv  /mnt/ramdisk/book/users01.dbf /home/oracle/
$ ln -s /home/oracle/users01.dbf /mnt/ramdisk/book/
$ ls -l /mnt/ramdisk/book/users01.dbf
lrwxrwxrwx 1 oracle oinstall 24 2017-11-01 15:34:03 /mnt/ramdisk/book/users01.dbf -> /home/oracle/users01.dbf

# cachedel /mnt/ramdisk/book/users01.dbf
# cachestats /mnt/ramdisk/book/users01.dbf
/mnt/ramdisk/book/users01.dbf            pages in cache: 0/32770 (0.0%)  [filesize=131080.0K, pagesize=4K]

--//清除os缓存.

--//重复前面的测试:

SYS@book> startup
ORACLE instance started.

Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

SYS@book> @ &r/spid
       SID    SERIAL# SPID       PID  P_SERIAL# C50
---------- ---------- ------ ------- ---------- --------------------------------------------------
       274          3 5371        21          2 alter system kill session '274,3' immediate;

SYS@book> select * from scott.dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

--//很奇怪看到的还是writing fd 10,换一个方式:

# ps -ef | grep ora_ck
oracle    5353     1  0 15:34 ?        00:00:00 ora_ckpt_book
root      5510  5031  0 15:47 pts/9    00:00:00 grep ora_ck

SYS@book> alter system checkpoint ;
System altered.

# peekfd 5353
reading fd 14:
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=0,data=ordered 0 0
/dev /dev tmpfs rw,relatime,mode=755 0 0
/proc /proc proc rw,relatime 0 0
/sys /sys sysfs rw,relatime 0 0
/proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
/dev/cciss/c0d0p6 /u01 ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=0,data=ordered 0 0
/dev/cciss/c0d0p1 /boot ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=0,data=ordered 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
/etc/auto.misc /misc autofs rw,relatime,fd=7,pgrp=4371,timeout=300,minproto=5,maxproto=5,indirect 0 0
-hosts /net autofs rw,relatime,fd=13,pgrp=4371,timeout=300,minproto=5,maxproto=5,indirect 0 0
tmpfs /mnt/ramdisk tmpfs rw,relatime,size=8388608k 0 0
none /sys/kernel/debug debugfs rw,relatime 0 0
nfsd /proc/fs/nfsd nfsd rw,relatime 0 0
/de
writing fd 14:
<msg time="2017-11-01T15:47:57.232+08:00" org_id="oracle" comp_id="rdbms" client_id='' type='UNKNOWN' level='16'
host_id='gxqyydg4' host_addr='192.168.100.78' module=''
pid='5353'>
Beginning global checkpoint up to RBA [0x2bc.649e.10], SCN: 13276962656

Wed Nov 01 15:47:57 2017
Beginning global checkpoint up to RBA [0x2bc.649e.10], SCN: 13276962656
<msg time="2017-11-01T15:47:57.241+08:00" org_id="oracle" comp_id="rdbms" client_id='' type='UNKNOWN' level='16'
host_id='gxqyydg4' host_addr='192.168.100.78' module=''
pid='5353'>
Completed checkpoint up to RBA [0x2bc.649e.10], SCN: 13276962656

Completed checkpoint up to RBA [0x2bc.649e.10], SCN: 13276962656

# ls -l /proc/5353/fd/14
ls: /proc/5353/fd/14: No such file or directory

--//很奇怪看不到对数据文件的读写.放弃.
--//至少目前可以看用户执行命令时的输出.放弃!!顺便看看汉字的输出问题.

SYS@book> select '文化123456' c20 from dual ;
C20
--------------------
文化123456

[01] y [06]  [10]  [17] ? [99] 睨 [87] / [15] X?[1c] R; [8d] B [03] xu [0b]  [01]  [11]  [01] &
[01] Q [01] ` [80]
T [03]  [01]  [08]  [01]  [03]  [03]  [03] C20 [07]  [07] xu [0b]  [01]  [11]  [01] 7?[1f]  [02]  [02]  [06]  [01] " [01]  [01] 鹻完 [07]
文化123456 [08]  [06] 雊^ [17]  [03]  [19]  [04]  [01]  [17]  [01]  [01]  [19]  [1d]  [03]  [1a]  [01] 6 [01] @?[0e]  [0c] ?[06]  [04]  [01]  [18]  [01]  [01] { [05]  [19]  [03]  [1b]  [01] 6 [01] @?[0e]  [0c]  [19] ORA-01403: no data found

--//汉字显示正常.

时间: 2024-08-01 11:22:16

[20171101]linux peekfd的简单使用.txt的相关文章

Linux curl使用简单介绍

<转自:http://www.cnblogs.com/-clq/archive/2012/01/29/2330827.html> Linux curl使用简单介绍[日期:2008-01-29]     来源:Linux公社  作者:notech Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1) 二话不说,先从这里开始吧! $ curl http://www.linuxidc.com 回车之后,www.linuxidc.com 的html就稀里哗啦地显示在屏幕上了  

[20170908]imp参数buffer的简单探究.txt

[20170908]imp参数buffer的简单探究.txt --//exp,imp已经很少在用,如果存在8i估计还会用一下,下面因为别人遇到升级忘记家buffer参数(8i),导致导入缓慢, --//当然还有许多因素,比如存在lob字段,不过还是简单探究参数buffer. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER -----------------------------

[20160921]linux下建立samba服务器.txt

[20160921]linux下建立samba服务器.txt --工作需要,需要在linux下配置samba服务.好久不做这些事情,做一个安装笔记: 1.安装samba软件包 # rpm -qa | grep samba samba-client-3.0.33-3.39.el5_8 samba-common-3.0.33-3.39.el5_8 samba-3.0.33-3.39.el5_8 --注意安装samba-3.0.33-3.39.el5_8需要 perl-Convert-ASN1-0.2

[20150430]列删除的简单恢复.txt

[20150430]列删除的简单恢复.txt SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -------------------------------------------------------------------------------- x86_64/Linux 2.4.xx          

[20150930]linux ln建立硬连接.txt

[20150930]linux ln建立硬连接.txt --前几天同事在建立测试环境时磁盘空间不足,而另外一个空间磁盘空间充足,我说可以通过ln建立软连接来解决这个问题. --这让我想起我以前管理数据库通过ln建立硬连接来避免oracle数据文件的删除,虽然现在我现在不用这种方式,不过还是做一些简单介 --绍. 1.关于linux的ln命令我不做介绍,自己看看手册. --仅仅说明一点,做硬链接不能跨文件系统. 2.实际上很简单,我拿测试环境做一次. RMAN> report schema; us

Linux下一个简单的多线程互斥锁的例子

本篇文章是对Linux下一个简单的多线程互斥锁的例子进行了分析介绍,需要的朋友可以参考下   复制代码 代码如下: #include <stdio.h> #include <pthread.h> pthread_mutex_t Device_mutex ; int count=0; void thread_func1() {    while(1)    {        pthread_mutex_lock(&Device_mutex);        printf(&q

《Linux指令从入门到精通》——4.2 Linux下的简单文字模式文本编辑器

4.2 Linux下的简单文字模式文本编辑器 Linux下的文本编辑器种类很多,功能的复杂程度和操作的难易度也不尽相同.在此我们将其大致分为可视和不可视两种.在本节中讲解的ed,jed,joe,pico和sed都属于不可视编辑器,不能进行全屏方式下的操作,操作相对简单.但可视编辑器的交互功能更好,典型的可视编辑器有vi和emacs,这将在下一节中讲述. 4.2.1 ed指令:简单的行文本编辑器 理解行编辑的概念,掌握ed指令进行简单的行文本编辑的方法 ed [参数] [文件名] ed指令是Lin

嵌入式linux-Zedboard板子运行linaro linux后运行简单的程序出错

问题描述 Zedboard板子运行linaro linux后运行简单的程序出错 操作系统已经运行起来了,可以实现如ls,rm,mkdir等基本功能.我在虚拟机上用交叉编译器编译了只有一个简单的printf输出的程序,但是之后放到板子上运行时,没有报错,但是也没有看到printf运行的结果.请问是什么问题呢?

Linux下一个简单的日志系统的设计及其C代码实现

1.概述 在大型软件系统中,为了监测软件运行状况及排查软件故障,一般都会要求软件程序在运行的过程中产生日志文件.在日志文件中存放程序流程中的一些重要信息,包括:变量名称及其值.消息结构定义.函数返回值及其执行情况.脚本执行及调用情况等.通过阅读日志文件,我们能够较快地跟踪程序流程,并发现程序问题.因此,熟练掌握日志系统的编写方法并快速地阅读日志文件,是对一个软件开发工程师的基本要求. 本文详细地介绍了Linux下一个简单的日志系统的设计方法,并给出了其C代码实现.本文为相关开发项目Linux下软