查看程序在运行过程中使用到的文件
2020-09-09 23:54
134 查看
查看程序在运行过程中使用到的文件
.title { text-align: center; margin-bottom: 0.2em }
.subtitle { text-align: center; font-size: medium; font-weight: bold; margin-top: 0 }
.todo { font-family: monospace; color: rgba(255, 0, 0, 1) }
.done { font-family: monospace; color: rgba(0, 128, 0, 1) }
.priority { font-family: monospace; color: rgba(255, 165, 0, 1) }
.tag { background-color: rgba(238, 238, 238, 1); font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal }
.timestamp { color: rgba(190, 190, 190, 1) }
.timestamp-kwd { color: rgba(95, 158, 160, 1) }
.org-right { margin-left: auto; margin-right: 0; text-align: right }
.org-left { margin-left: 0; margin-right: auto; text-align: left }
.org-center { margin-left: auto; margin-right: auto; text-align: center }
.underline { text-decoration: underline }
#postamble p, #preamble p { font-size: 90%; margin: 0.2em }
p.verse { margin-left: 3% }
pre { border: 1px solid rgba(204, 204, 204, 1); box-shadow: 3px 3px 3px rgba(238, 238, 238, 1); padding: 8pt; font-family: monospace; overflow: auto; margin: 1.2em }
pre.src { position: relative; overflow: visible; padding-top: 1.2em }
pre.src:before { display: none; position: absolute; background-color: rgba(255, 255, 255, 1); top: -10px; right: 10px; padding: 3px; border: 1px solid rgba(0, 0, 0, 1) }
pre.src:hover:before { display: inline }
pre.src-asymptote:before { content: "Asymptote" }
pre.src-awk:before { content: "Awk" }
pre.src-C:before { content: "C" }
pre.src-clojure:before { content: "Clojure" }
pre.src-css:before { content: "CSS" }
pre.src-D:before { content: "D" }
pre.src-ditaa:before { content: "ditaa" }
pre.src-dot:before { content: "Graphviz" }
pre.src-calc:before { content: "Emacs Calc" }
pre.src-emacs-lisp:before { content: "Emacs Lisp" }
pre.src-fortran:before { content: "Fortran" }
pre.src-gnuplot:before { content: "gnuplot" }
pre.src-haskell:before { content: "Haskell" }
pre.src-hledger:before { content: "hledger" }
pre.src-java:before { content: "Java" }
pre.src-js:before { content: "Javascript" }
pre.src-latex:before { content: "LaTeX" }
pre.src-le
56c
dger:before { content: "Ledger" }
pre.src-lisp:before { content: "Lisp" }
pre.src-lilypond:before { content: "Lilypond" }
pre.src-lua:before { content: "Lua" }
pre.src-matlab:before { content: "MATLAB" }
pre.src-mscgen:before { content: "Mscgen" }
pre.src-ocaml:before { content: "Objective Caml" }
pre.src-octave:before { content: "Octave" }
pre.src-org:before { content: "Org mode" }
pre.src-oz:before { content: "OZ" }
pre.src-plantuml:before { content: "Plantuml" }
pre.src-processing:before { content: "Processing.js" }
pre.src-python:before { content: "Python" }
pre.src-R:before { content: "R" }
pre.src-ruby:before { content: "Ruby" }
pre.src-sass:before { content: "Sass" }
pre.src-scheme:before { content: "Scheme" }
pre.src-screen:before { content: "Gnu Screen" }
pre.src-sed:before { content: "Sed" }
pre.src-sh:before { content: "shell" }
pre.src-sql:before { content: "SQL" }
pre.src-sqlite:before { content: "SQLite" }
pre.src-forth:before { content: "Forth" }
pre.src-io:before { content: "IO" }
pre.src-J:before { content: "J" }
pre.src-makefile:before { content: "Makefile" }
pre.src-maxima:before { content: "Maxima" }
pre.src-perl:before { content: "Perl" }
pre.src-picolisp:before { content: "Pico Lisp" }
pre.src-scala:before { content: "Scala" }
pre.src-shell:before { content: "Shell Script" }
pre.src-ebnf2ps:before { content: "ebfn2ps" }
pre.src-cpp:before { con
56c
tent: "C++" }
pre.src-abc:before { content: "ABC" }
pre.src-coq:before { content: "Coq" }
pre.src-groovy:before { content: "Groovy" }
pre.src-bash:before { content: "bash" }
pre.src-csh:before { content: "csh" }
pre.src-ash:before { content: "ash" }
pre.src-dash:before { content: "dash" }
pre.src-ksh:before { content: "ksh" }
pre.src-mksh:before { content: "mksh" }
pre.src-posh:before { content: "posh" }
pre.src-ada:before { content: "Ada" }
pre.src-asm:before { content: "Assembler" }
pre.src-caml:before { content: "Caml" }
pre.src-delphi:before { content: "Delphi" }
pre.src-html:before { content: "HTML" }
pre.src-idl:before { content: "IDL" }
pre.src-mercury:before { content: "Mercury" }
pre.src-metapost:before { content: "MetaPost" }
pre.src-modula-2:before { content: "Modula-2" }
pre.src-pascal:before { content: "Pascal" }
pre.src-ps:before { content: "PostScript" }
pre.src-prolog:before { content: "Prolog" }
pre.src-simula:before { content: "Simula" }
pre.src-tcl:before { content: "tcl" }
pre.src-tex:before { content: "TeX" }
pre.src-plain-tex:before { content: "Plain TeX" }
pre.src-verilog:before { content: "Verilog" }
pre.src-vhdl:before { content: "VHDL" }
pre.src-xml:before { content: "XML" }
pre.src-nxml:before { content: "XML" }
pre.src-conf:before { content: "Configuration File" }
table { border-collapse: collapse }
caption.t-above { caption-side: top }
c
56c
aption.t-bottom { caption-side: bottom }
td, th { vertical-align: top }
th.org-right { text-align: center }
th.org-left { text-align: center }
th.org-center { text-align: center }
td.org-right { text-align: right }
td.org-left { text-align: left }
td.org-center { text-align: center }
dt { font-weight: bold }
.footpara { display: inline }
.footdef { margin-bottom: 1em }
.figure { padding: 1em }
.figure p { text-align: center }
.equation-container { display: table; text-align: center; width: 100% }
.equation { vertical-align: middle }
.equation-label { display: table-cell; text-align: right; vertical-align: middle }
.inlinetask { padding: 10px; border: 2px solid rgba(128, 128, 128, 1); margin: 10px; background: rgba(255, 255, 204, 1) }
#org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap }
textarea { overflow-x: auto }
.linenr { font-size: smaller }
.code-highlighted { background-color: rgba(255, 255, 0, 1) }
.org-info-js_info-navigation { border-style: none }
#org-info-js_console-label { font-size: 10px; font-weight: bold; white-space: nowrap }
.org-info-js_search-highlight { background-color: rgba(255, 255, 0, 1); color: rgba(0, 0, 0, 1); font-weight: bold }
.org-svg { width: 90% }
4. 总结
查看程序在运行过程中使用到的文件
Table of Contents
1 场景
试想这个场景
- 写了一个脚本在运行
- 脚本运行时间需要很长,并且你不能停下脚本(会有中断问题)
- 这时候你想知道自己的脚本进程在处理什么文件,在做什么事情,该怎么办呢?
2 想知道进程在读写什么文件
首先 使用
ps aux 或者 ps ef查看自己的进程 id
然后到
/proc/目录中下查看相应进程的进程运行数据
ps aux数据
wudanya+ 3166 0.0 0.0 107956 616 ? S 22:04 0:00 sleep 180 wudanya+ 3189 0.0 0.0 107956 616 pts/3 S+ 22:06 0:00 sleep 1000000 wudanya+ 3191 0.0 0.0 112728 972 pts/5 R+ 22:06 0:00 grep --color=auto sleep
第二列就是每个进程的 pid ,在系统中是唯一的
查看
/proc/[pid]/fd目录
如图, 可以看到,进程打开了 4 个文件描述符
其中 0、1、2 分别代表 标准输入、输出、错误(规定)
25 代表的是一个虚拟终端
3 打开的是一个文件
这样就可以知道你打开的是什么文件了
是不是很简单呢
3 我怎么知道文件正在读取还是写入呢
这还用问,当然是看代码了
开个玩笑
咱们这次是说不用看代码就可以看出来在写入什么文件,在读取什么文件
3.1 lsof -p pid
[wudanyang@bogon ~]$ lsof -p 3352 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME tail 3352 wudanyang cwd DIR 253,0 4096 4731473 /home/wudanyang tail 3352 wudanyang rtd DIR 253,0 240 64 / tail 3352 wudanyang txt REG 253,0 66824 12829983 /usr/bin/tail tail 3352 wudanyang mem REG 253,0 106075056 12587626 /usr/lib/locale/locale-archive tail 3352 wudanyang mem REG 253,0 2156160 44517 /usr/lib64/libc-2.17.so tail 3352 wudanyang mem REG 253,0 163400 44510 /usr/lib64/ld-2.17.so tail 3352 wudanyang 0u CHR 136,3 0t0 6 /dev/pts/3 tail 3352 wudanyang 1u CHR 136,3 0t0 6 /dev/pts/3 tail 3352 wudanyang 2u CHR 136,3 0t0 6 /dev/pts/3 tail 3352 wudanyang 3r REG 253,0 0 5171247 /home/wudanyang/a tail 3352 wudanyang 4r a_inode 0,10 0 5338 inotify tail 3352 wudanyang 25u CHR 5,2 0t0 7061 /dev/ptmx
前三列可以不用管,第四列是打开的描述符,可以看到
FD:
u | 读/写 |
r | 只读 |
w | 只写 |
W | 获得写锁 |
OK,搞定,可以看到咱们程序打开了一个
/home/wudanyang/a文件只读描述符
3.2 使用 strace -p pid 看一下系统调用
通过系统调用查看一下当前正在执行的系统调用,也可以看到是 读还是写。上图中是一个读取的系统调用,参数是文件描述符 4
4 总结
- 日常工作中会经常遇到这种需求,总结一下
/proc/[pid]/
不止有 fd ,可以继续深入了解一下
===
作者: 吴丹阳 https://www.cnblogs.com/wudanyang
更新时间: 2020-09-10 Thu 00:09
Emacs 28.0.50 (Org mode 9.3.7)
===
天行健,君子以自强不息。
地势坤,君子以厚德载物。
===
相关文章推荐
- HDFS设计思路,HDFS使用,查看集群状态,HDFS,HDFS上传文件,HDFS下载文件,yarn web管理界面信息查看,运行一个mapreduce程序,mapreduce的demo
- CLR基础,CLR运行过程,使用dos命令创建、编译、运行C#文件,查看IL代码
- HDFS设计思路,HDFS使用,查看集群状态,HDFS,HDFS上传文件,HDFS下载文件,yarn web管理界面信息查看,运行一个mapreduce程序,mapreduce的demo
- at 命令来安排命令、脚本或程序在指定的日期和时间运行。您也可以使用此命令查看现有的计划任务。
- SQL2000安装过程中出现“以前进行的程序创建了挂起的文件操作,运行安装程序前,必须重新启动”的解决办法
- iOS AppDelegate程序生命运行过程及使用时机
- 使用.bat文件在Windows下运行Java程序时怎样避免DOS窗口
- C#使用 SQLite 数据库 开发的配置过程及基本操作类,实例程序:工商银行贵金属行情查看小工具
- AndroidStudio使用过程中java类突然报红,但是程序可运行
- 问题:在pycharm中运行程序,两个.py文件属于同一目录且都存在,在一个.py文件无法使用from...import命令引用另一个.py文件,即from...import...有红色波浪线
- 使用C#在程序运行时创建文件关联
- EWARM IAR5.4编译链接过程, 程序运行阶段, ICF ilink配置文件
- 查看Eclipse 运行java程序时使用的命令
- 使用.bat文件在Windows下运行Java程序时怎样避免DOS窗口
- 【已解决】安装Scrapy过程中出错:ERROR: ‘xslt-config’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
- VMware Workstation 无法连接到虚拟机。请确保您有权运行该程序、访问该程序使用的所有目录以及访问所有临时文件目录。 VMware Authorization Service 当前未运行
- 在使用win10 cmd的时候python报错:python不是内部或外部指令,也不是可运行的程序或批处理文件
- 查看程序运行失败后core文件给出的信息
- 在Linux下获取当前运行程序可执行文件全路径(不使用real_path()函数)
- win7里边使用telnet命令为什么提示telnet不是内部或外部命令,也不是可运行的程序或批处理文件?解决