freebsd:按进程ID运行进程的当前目录

发布于 2024-07-29 12:28:36 字数 43 浏览 4 评论 0原文

我有 freebsd 中正在运行的进程的 pid。 如何获取当前目录?

I have the pid of a running process in freebsd.
How do I obtain its current directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

围归者 2024-08-05 12:28:36

您可以使用 lsof 获取当前工作目录的 inode 号。

fstat -p $PID

看起来 lsof 将为您提供当前工作目录的人类可读形式,但我们没有在任何本地 FreeBSD 计算机上安装它,所以我不能验证一下。

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

fstat -p $PID

It looks like lsof will give you a human readable form of the current working directory, but we don't have that installed on any of the local FreeBSD machines, so I can't verify that.

流星番茄 2024-08-05 12:28:36

fstat可以找到inode号和文件系统,find可以找到正确的目录。

试试这个:

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

当以非 root 身份运行时,find 可能会输出相当多的“权限被拒绝”消息,可以通过插入 close(STDERR); 来避免这些消息
$F[3] 前面(第一个单引号之后)。

fstat can find the inode number and filesystem, and find can find the correct directory.

Try this:

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

When run as non-root, find will probably output quite a few "Permission denied" messages which can be avoided by inserting close(STDERR);
in front of the $F[3] (after the first single quote).

翻了热茶 2024-08-05 12:28:36

在 FreeBSD 的最新版本中,您可以使用 procstat -f $PID ,它会显示路径名(如果它仍在内核名称缓存中)。

In more recent versions of FreeBSD, you can use procstat -f $PID, which shows the pathname if it is still in the kernel name cache.

缱绻入梦 2024-08-05 12:28:36

/proc/$PID/cwd 包含指向程序当前工作目录的符号链接。

/proc/$PID/cwd contains a symlink to the programmes current working directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文