I assumed the umask() function is a:

shell function containing a variable commonly referred to as file creation mask

but I was wrong because umask() is not a shell function and doesn't contain such variable.

If the umask() function is not a "shell function" is it true to name it a "kernel function"?


There is no such thing as a "kernel function", unless you mean this.

umask(2) is a system call. And it was so since the dawn of time [1].

But it doesn't have to be that way -- you can implement it by having the actual bitmask be part of a chunk of memory that's always mapped at the same address and preserved through execve(2), and have the open(2), creat(2), etc userland wrappers pick it up from there. That would be just as POSIX-compliant.

[1] in the original implementation, the u.u_cmask field that function sets is only used in a single place elsewhere -- in the "Make a new file" maknode() function.

  • 2
    I quibble with your chronology.  Time began in the early 1970s (or maybe even the late 1960s); umask didn't exist until at least the late 1970s. – G-Man Says 'Reinstate Monica' Dec 3 '18 at 4:57

The manual for umask says:

A child process created via fork(2) inherits its parent's umask. The umask is left unchanged by execve(2).

Therefore because it persists after a call to exec (execve), it must be implemented in the kernel, as all exec calls replace the running program (except some structures stored in the kernel).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.