Freebsd: current dynamic process loop by process id

I have a pid of a running process in freebsd. How to get the current directory?

+3
source share
4 answers

You can get the inode number of the current working directory with

fstat -p $PID

It seems that lsof will provide you with a human-readable form of the current working directory, but we do not have it on any of the local FreeBSD machines, so I cannot verify this.

+3
source

fstat can find the inode number and file system, and find can find the correct directory.

Try the following:

fstat -p $$|perl -ane '$F[3] eq "wd" && system("find",$F[4],"-xdev","-inum",$F[5],"-print");'

-root, find, , " ", , close(STDERR); $F[3] ( ).

+3

In later versions of FreeBSD, you can use procstat -f $PIDwhich shows the path if it is still in the kernel name cache.

+1
source

/ proc / $ PID / cwd contains a symbolic link to the current working directory of programs.

-1
source

Source: https://habr.com/ru/post/1713137/


All Articles