What is the difference between EACCES and EPERM exactly? EPERM is described here as "not super user", but I would usually associate that with EACCES. In fact, I can't recall ever seeing an EPERM in real life.
2 Answers
EACCES
is almost always used when the system call was passed a path that was inaccessible by the current user.
EPERM
is used in various other situations where you need to be root to perform an action, e.g.
kill()
on a process that you don't ownlink()
on a directoryreboot()
-
Well, link() on a directory isn't normally allowed to root either, but this answer seems good otherwise. Jan 17, 2017 at 19:52
-
@BruceFields Depends on the OS. Some have allowed root to hardlink directories. (Not even just historically; macOS actively uses this feature for backups.)– user149341Jan 17, 2017 at 22:20
-
Good point! Maybe I should have said: "link() on a directory returns EPERM even on OS's where hardlinks aren't allowed even to root". Jan 18, 2017 at 21:22
-
Note that significant portions of the
sockets(7)
subsystem also tend to returnEACCES
whenEPERM
might make more sense (e.g. creating a raw socket, binding a low network port, etc.). I imagine it's a Berkeley-ism.– KevinJan 24, 2018 at 19:47 -
The Linux capabilities(7)
figure into execve(2)
so that if the exec'ing process lacks the correct inheritance/bounding-set/ambient to set the file-capabilities:
"If the process did not obtain the full set of file permitted capabilities, then execve(2) fails with the error EPERM."