linux:获取已运行进程的umask?
如何检查当前正在运行的程序的umask?
[更新:另一个进程,不是当前进程。]
How can I check the umask of a program which is currently running?
[update: another process, not the current process.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以将 gdb 附加到正在运行的进程,然后在调试器中调用 umask:(
注意:在此示例中,18 对应于
O22
的 umask)这表明可能有一种非常丑陋的方法来获取使用 ptrace 的 umask。
You can attach gdb to a running process and then call umask in the debugger:
(note: 18 corresponds to a umask of
O22
in this example)This suggests that there may be a really ugly way to get the umask using ptrace.
从 Linux 内核 4.7 开始,umask 在
/proc//status
中可用。Beginning with Linux kernel 4.7, the umask is available in
/proc/<pid>/status
.来自 GNU C 库手册:
不过,
getumask
是 glibc 特定的。 因此,如果您重视可移植性,那么不可重入的解决方案是唯一的解决方案。编辑:我刚刚在 Linux 源代码中查找了
->umask
。 没有任何地方可以让您获得不同进程的 umask。 另外,没有getummask
; 显然这是赫德独有的事情。From the GNU C Library manual:
getumask
is glibc-specific, though. So if you value portability, then the non-reentrant solution is the only one there is.Edit: I've just grepped for
->umask
all through the Linux source code. There is nowhere that will get you the umask of a different process. Also, there is nogetumask
; apparently that's a Hurd-only thing.如果您是当前进程,则可以将文件写入 /tmp 并检查其设置。 更好的解决方案是调用 umask(3) 并传递零 - 该函数返回调用之前的设置 - 然后通过将该值传递回 umask 来重置它。
另一个进程的 umask 似乎没有暴露。
If you're the current process, you can write a file to /tmp and check its setting. A better solution is to call umask(3) passing zero - the function returns the setting prior to the call - and then reset it back by passing that value back into umask.
The umask for another process doesn't seem to be exposed.
一位同事刚刚向我展示了这个命令行模式。 我总是运行 emacs,所以如下例所示。
perl
是我的贡献:A colleague just showed me this command line pattern for this. I always have emacs running, so that's in the example below. The
perl
is my contribution:至少在内核 4.18 中,有一个选项可以搜索状态 proc 文件:
grep Umask /proc//status
At least with Kernel 4.18, there is an option to search the status proc file:
grep Umask /proc/<PID>/status