2017年1月8日 星期日

[Linux 常見問題] Find out current working directory of a running process?

Source From Here
Question
What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.

How-To
There are 3 methods that I'm aware of:
- pwdx: report current working directory of a process
// pwdx
# pwdx 16497
16497: /home/john/Tools/L2ParserSrv

- lsof: list open files of process
// -p s: excludes or selects the listing of files for the processes whose optional process IDentification (PID) numbers are in the comma-separated set s
# lsof -p 16497 | grep cwd
...
java 16497 root cwd DIR 253,2 4096 2149506102 /home/john/Tools/L2ParserSrv

- /proc
// -e, --canonicalize-existing: canonicalize by following every symlink in every component of the given name recursively, all components must exist
# readlink -e /proc/16497/cwd/
/home/john/Tools/L2ParserSrv


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...