[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 <>
URL :
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 :
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
--//漢字顯示正常.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2146695/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux下GPG的簡單使用Linux
- [20171101]修改oracle口令安全問題.txtOracle
- linux中的top命令簡單使用Linux
- Linux中ps命令的簡單使用Linux
- linux中history命令的簡單使用Linux
- [20160902]簡單探究linux的free命令.txtLinux
- sqlplus中的變數定義和簡單使用.txtSQL變數
- Linux下getopt()函式的簡單使用Linux函式
- iPython在Linux下的簡單使用PythonLinux
- C#之使用RichTextBox 實現簡單的txt編輯器C#
- Linux簡單的操作Linux
- Kdevelop的簡單使用和簡單除錯dev除錯
- docker的簡單使用Docker
- postman的簡單使用Postman
- RecyclerView的簡單使用View
- git的簡單使用Git
- LayUi的簡單使用UI
- RocketMQ的簡單使用MQ
- Vue簡單的使用Vue
- Cookie的簡單使用Cookie
- HttpClient的簡單使用HTTPclient
- explain for 的簡單使用AI
- OD的簡單使用
- Linux V4l2簡單使用Linux
- [20190301]簡單測試linux fsfreeze命令.txtLinux
- linux程式多執行緒互斥鎖的簡單使用Linux執行緒
- Linux簡單命令Linux
- shell script的簡單使用
- uuid的簡單使用UI
- Mackdown簡單的使用教程Mac
- react hooks 的簡單使用ReactHook
- vue框架的簡單使用Vue框架
- phprpc的簡單使用PHPRPC
- opencv CvMLData的簡單使用OpenCVLDA
- 【SQLite】SQLite的簡單使用SQLite
- [20150629]簡單的加密連線.txt加密
- mysql的event的簡單使用MySql
- linux下mail的簡單用法LinuxAI