The executable files that
gcc creates have execution permissions
which are different than the permissions that the source file has.
gcc set these permissions ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Four things intervene to determine the permission of a file.
openfor regular files,
mkdirfor directories, etc.).
022removes the group-write and other-write permission. An umask of
007leaves the group-write permission but makes the file completely off-limits to others.
chmodexplicitly to change the permissions to whatever it wants. The user who owns a file can set its permissions freely.
Some popular choices of permission sets for step 1 are:
It's the umask that causes files not to be world-readable even though applications can and usually do include the others-write permission in the file creation permissions.
In the case of gcc, the output file is first created with permissions 666 (masked by the umask), then later chmod'ed to make it executable. Gcc could create an executable directly, but doesn't: it only makes the file executable when it's finished writing it, so that you don't risk starting to execute the program while it's incomplete.
I'm not positive what you're asking; you mean how does it have permission to set them? A file's owner can set the permissions to whatever they want.
gcc is running under your user account, so the file it creates is owned by you, and it has permission to do anything your account can do, including setting permissions on your files
As @AshRj's comment above says, this depends on the default permissions the account has set. Essentially what is done is to start with all permissions (that includes, specifically,
x for user/group/others) and turn off permissions specified by
umask(2) (also see
bash(1)). Today (each user has their own private group)
umask is typically set to 002 (only deny
wfor others), so the permissions of the executable turn out
rwxrwxr-x, independent of the permissions on the sources. If other files are created (e.g. by the editor) the starting permissions lack
x at all (a random text file isn't supposed to be run), so permissions would turn out