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


沒有留言:

張貼留言

[Linux 常見問題] sudo: Sorry, you must have a tty to run sudo Error on a Linux and Unix

Source From  Here   Preface   I‘m trying to run the following command:  #   ssh  user@box.example.com  sudo command1 /path/to/file But, a...