linuxunixumask

linux: getting umask of an already running process?


How can I check the umask of a program which is currently running?

[update: another process, not the current process.]


Solution

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