Linux:获取已经运行的进程的umask?
时间:2020-03-06 15:03:27 来源:igfitidea点击:
如何检查当前正在运行的程序的umask?
[更新:另一个进程,而不是当前进程。]
解决方案
如果我们是当前进程,则可以将文件写入/ tmp并检查其设置。更好的解决方案是调用umask(3)传递零,函数将在调用之前返回设置,然后通过将该值传递回umask来将其重置。
另一个进程的umask似乎没有公开。
从GNU C库手册中:
Here is an example showing how to read the mask with umask without changing it permanently: mode_t read_umask (void) { mode_t mask = umask (0); umask (mask); return mask; } However, it is better to use getumask if you just want to read the mask value, because it is reentrant (at least if you use the GNU operating system).
不过,getumask
是特定于glibc的。因此,如果我们重视可移植性,那么唯一的解决方案就是不可重入的解决方案。
编辑:我只是通过Linux源代码对-> umask
进行了grep化。没有任何地方会让我们陷入另一种进程的困境。而且,没有getumask
;显然,这只是一个赫德的事情。
我们可以将gdb添加到正在运行的进程,然后在调试器中调用umask:
(gdb) call umask(0) [Switching to Thread -1217489200 (LWP 11037)] = 18 (gdb) call umask(18) = 0 (gdb)
(注意:18 = O22)
这表明使用ptrace获取umask可能有一种非常丑陋的方法。