linux: getting umask of an already running process? linux: getting umask of an already running process? unix unix

linux: getting umask of an already running process?


You can attach gdb to a running process and then call umask in the debugger:

(gdb) attach <your pid>...(gdb) call umask(0)[Switching to Thread -1217489200 (LWP 11037)]$1 = 18 # this is the umask(gdb) call umask(18) # reset umask$2 = 0(gdb) 

(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.


Beginning with Linux kernel 4.7, the umask is available in /proc/<pid>/status.


From the GNU C Library manual:

Here is an example showing how to read the mask with umask without changing it permanently:

mode_tread_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 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 no getumask; apparently that's a Hurd-only thing.