[20241014]strace使用小技巧参数y.txt

来源:这里教程网 时间:2026-03-03 20:42:04 作者:

[20241014]strace使用小技巧参数y.txt --//昨天测试sqlplus spool的相关问题,想起应该使用strace跟踪看看,了解一些操作细节。 --//我以前看Franck Pachot的blog,好像strace有1个参数启动可以看到打开的文件句柄带上真实的文件名,这样比较直观。 --//我当时测试服务器是oracle kennel 5.9版本,strace版本很低,没有这个功能,记忆有点混乱,我现在使用centos 7.3, --//看看该机器带的strace是否支持这个功能,我连参数名都有点忘记了,看看相关文档顺便写一篇文章。 $ man strace     ... -y Print paths associated with file descriptor arguments. --//参数y支持这个特性,测试看看。 1.环境: SCOTT@book01p> @ ver2 ============================== PORT_STRING                   : x86_64/Linux 2.4.xx VERSION                       : 21.0.0.0.0 BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production Version 21.3.0.0.0 BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production CON_ID                        : 0 PL/SQL procedure successfully completed. $ cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) $ echo -e "$SQLPATH\n$ORACLE_PATH" /home/oracle/sqllaji:/home/oracle/sqllaji/tpt /home/oracle/sqllaji:/home/oracle/sqllaji/tpt 2.测试: --//session 1: SCOTT@book01p> @ spid        SID    SERIAL# PROCESS                  SERVER    SPID                               PID  P_SERIAL# C50 ---------- ---------- ------------------------ --------- ------------------------------ ------- ---------- --------------------------------------------------        142      58300 4673                     DEDICATED 4675                                65          4 alter system kill session '142,58300' immediate; SCOTT@book01p> host pwd /home/oracle/study/202410 SCOTT@book01p> host touch /home/oracle/study/202410/tmp123.txt SCOTT@book01p> host touch /home/oracle/sqllaji/tmp123.txt SCOTT@book01p> host touch /home/oracle/sqllaji/tpt/tmp123.txt --//window  1: $  strace -f -p 4673  -y Process 4673 attached --//注意跟踪进程号4673。 --//session 1: SCOTT@book01p> spool ./tmp123.txt --//window  1:  $  strace -f -p 4673 -y Process 4673 attached read(0</dev/pts/8>, "spool ./tmp123.txt\n", 1024) = 19 access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = 0 access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = 0 stat("/home/oracle/sqllaji/./tmp123.txt", {st_mode=S_IFREG|0644, st_size=25, ...}) = 0 stat("/home/oracle/sqllaji/./", {st_mode=S_IFDIR|0755, st_size=16384, ...}) = 0 open("/home/oracle/sqllaji/./tmp123.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ fcntl(10</home/oracle/sqllaji/tmp123.txt>, F_SETFD, FD_CLOEXEC) = 0 fstat(10</home/oracle/sqllaji/tmp123.txt>, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f14a33f8000 write(1</dev/pts/8>, "SCOTT@book01p> ", 15) = 15 read(0</dev/pts/8>, --//这样优先打开open("/home/oracle/sqllaji/./tmp123.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 10 --//open对应句柄10,这样显示的内容句柄号跟着文件名就比较直观. --//session 1: SCOTT@book01p> spool off SCOTT@book01p> host rm /home/oracle/study/202410/tmp123.txt SCOTT@book01p> host rm home/oracle/sqllaji/tmp123.txt SCOTT@book01p> host rm /home/oracle/sqllaji/tpt/tmp123.txt SCOTT@book01p> spool ./tmp123.txt --//window  1: $  strace -f -p 4673 -y Process 4673 attached read(0</dev/pts/8>, "spool ./tmp123.txt\n", 1024) = 19 access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/tpt/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/tpt/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/tpt/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) access("/home/oracle/sqllaji/tpt/./tmp123.txt", F_OK) = -1 ENOENT (No such file or directory) --//使用access分别尝试4次,不存在。 stat("./tmp123.txt", 0x7ffc62357980)    = -1 ENOENT (No such file or directory) stat("./", {st_mode=S_IFDIR|0755, st_size=39, ...}) = 0 open("./tmp123.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 10 --//返回看看本地是否存在,使用stat。 fcntl(10</home/oracle/study/202410/tmp123.txt>, F_SETFD, FD_CLOEXEC) = 0 fstat(10</home/oracle/study/202410/tmp123.txt>, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f14a33f8000 write(1</dev/pts/8>, "SCOTT@book01p> ", 15) = 15 read(0</dev/pts/8>,

相关推荐