====== Ubuntu - Processes - Inspect the umask of a running process ====== ===== Objective ===== To inspect the umask of a running process ---- ===== Background ===== The umask, or ‘user file creation mask‘, allows the user to influence the permissions given to newly created files and directories. Any bits that are set within the umask are automatically cleared within the file mode. Like file modes, umasks are normally written in octal. ---- ===== Scenario ===== Suppose that you wish to check that a daemon is executing with the intended umask. It has a process ID of 29964 and is executing the file /usr/local/bin/testd. ---- ===== Method ===== The usual place to look for information about a process would be /proc. Unfortunately the umask is not (currently) exposed through this interface, so it is necessary to look elsewhere. There is a POSIX function called umask [http://pubs.opengroup.org/onlinepubs/009695399/functions/umask.html] which returns the umask of the process that called it. It is not able to directly interrogate other processes, but you can use a debugger to call it in the context of another process. This is a moderately invasive method as it involves halting the process in question and making a temporary change to its umask. In most cases this will cause no lasting harm, but obviously that depends on the nature of the process. You will need to know the process ID and the pathname of the file being executed. It is not necessary for the executable to include debugging symbols or to be compiled with optimisation turned off. For the scenario described above, and using GDB [http://www.gnu.org/software/gdb/] as the debugger, issue the following command to start an interactive debugging session: gdb /usr/local/bin/testd 29964 The command prompt should change to (gdb). You can now instruct the process that is being debugged to call umask: (gdb) call umask(0) This has the unwanted effect of setting the umask to zero, but also returns the previous value of the umask: $1 = 18 Note that the output is in decimal, so 18 corresponds to what would normally be written in octal as 0022. Having obtained this information you should now restore the umask to its previous value and then exit from GDB using the quit command: (gdb) call umask(18) $2 = 0 (gdb) quit