1 .\" Copyright (c) 2006, 2008, Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" (A few fragments remain from an earlier (1992) version written in
3 .\" 1992 by Drew Eckhardt <drew@cs.colorado.edu>.)
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\" Modified by Michael Haardt <michael@moria.de>
8 .\" Modified Sat Jul 24 12:51:53 1993 by Rik Faith <faith@cs.unc.edu>
9 .\" Modified Tue Oct 22 22:39:04 1996 by Eric S. Raymond <esr@thyrsus.com>
10 .\" Modified Thu May 1 06:05:54 UTC 1997 by Nicolás Lichtmaier
11 .\" <nick@debian.com> with Lars Wirzenius <liw@iki.fi> suggestion
12 .\" 2006-05-13, mtk, substantial rewrite of description of 'mask'
13 .\" 2008-01-09, mtk, a few rewrites and additions.
14 .TH UMASK 2 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
16 umask \- set file mode creation mask
19 .RI ( libc ", " \-lc )
22 .B #include <sys/stat.h>
24 .BI "mode_t umask(mode_t " mask );
28 sets the calling process's file mode creation mask (umask) to
30 & 0777 (i.e., only the file permission bits of
32 are used), and returns the previous value of the mask.
37 and other system calls that create files
38 .\" e.g., mkfifo(), creat(), mknod(), sem_open(), mq_open(), shm_open()
39 .\" but NOT the System V IPC *get() calls
40 to modify the permissions placed on newly created files or directories.
41 Specifically, permissions in the umask are turned off from
49 Alternatively, if the parent directory has a default ACL (see
51 the umask is ignored, the default ACL is inherited,
52 the permission bits are set based on the inherited ACL,
53 and permission bits absent in the
55 argument are turned off.
56 For example, the following default ACL is equivalent to a umask of 022:
64 Combining the effect of this default ACL with a
66 argument of 0666 (rw-rw-rw-), the resulting file permissions would be 0644
69 The constants that should be used to specify
74 The typical default value for the process umask is
75 .BR S_IWGRP " | " S_IWOTH
77 In the usual case where the
85 .BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IWGRP " | " S_IROTH " | " S_IWOTH
89 (octal 0666) when creating a new file, the permissions on the
90 resulting file will be:
94 .BR S_IRUSR " | " S_IWUSR " | " S_IRGRP " | " S_IROTH
98 (because 0666 & \(ti022 = 0644; i.e. rw\-r\-\-r\-\-).
100 This system call always succeeds and the previous value of the mask
103 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
105 A child process created via
107 inherits its parent's umask.
108 The umask is left unchanged by
111 It is impossible to use
113 to fetch a process's umask without at the same time changing it.
116 would then be needed to restore the umask.
117 The nonatomicity of these two steps provides the potential
118 for races in multithreaded programs.
120 Since Linux 4.7, the umask of any process can be viewed via the
123 .IR /proc/ pid /status .
124 Inspecting this field in
126 allows a process to retrieve its umask without at the same time changing it.
128 The umask setting also affects the permissions assigned to POSIX IPC objects
134 and UNIX domain sockets
136 created by the process.
137 The umask does not affect the permissions assigned
138 to System\ V IPC objects created by the process (using