To understand umask, you first need to understand the structure of processes in Unix/Linux. Which is to say, they form a tree-like structure. Each process needs to have a parent, which is the process that spawned it. (With the exception of the first process, init
). Each process may or may not spawn more processes, called children.
Each process has a mask property. This is what is queried or set using the umask command.
Processes inherit the mask of their parent. They can then change their own mask. For example, there is a umask()
C function that can change the mask of the program you are writing, without needing to call umask
from the shell.
A child process cannot affect the mask of their parent. Therefore, changing the mask of a process will not affect the entire system. It will only affect any future child processes.
Since the purpose of a shell is to be able to create and control other processes, a umask
command is built in to most shells. This isn't required for a shell, it is possible to write a basic shell that has no umask
function. But such a shell would not be considered useful as a general-purpose shell for logging in and administering a system.
You can test what I'm saying yourself, using the fact that a shell like Bash can spawn other Bash shells (or whatever other shell you like):
- Open a terminal
- Run the
umask
command to query the current value
- Run
bash
(or whatever) to spawn a child shell
- Run
umask
to check the value of the child's mask
- Set the child's mask to something else, eg run
umask 0000
- Run
umask
to check the child's mask again
- Exit from the child shell (run
exit
or press Ctrl-d
)
- You are now back in the parent shell again. Run
umask
to check its mask
Useful references: