processes:inspect_the_umask_of_a_running_process
Differences
This shows you the differences between two versions of the page.
processes:inspect_the_umask_of_a_running_process [2016/07/04 15:28] – created peter | processes:inspect_the_umask_of_a_running_process [2019/12/01 22:35] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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. | ||
- | |||
- | ===== 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:// | ||
- | |||
- | 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:// | ||
- | |||
- | <code bash> | ||
- | gdb / | ||
- | </ | ||
- | |||
- | The command prompt should change to (gdb). | ||
- | |||
- | <code bash> | ||
- | (gdb) call umask(0) | ||
- | </ | ||
- | |||
- | This has the unwanted effect of setting the umask to zero, but also returns the previous value of the umask: | ||
- | |||
- | <code bash> | ||
- | $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: | ||
- | |||
- | <code bash> | ||
- | (gdb) call umask(18) | ||
- | $2 = 0 | ||
- | (gdb) quit | ||
- | </ | ||
processes/inspect_the_umask_of_a_running_process.1467646120.txt.gz · Last modified: 2020/07/15 09:30 (external edit)