17

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.

George Simms
  • 3,930
  • 4
  • 21
  • 35
  • just want to add the [GNU source for the error codes](https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html) as I got here by looking for what EPERM stands for. – Wolfson Apr 08 '21 at 11:21

2 Answers2

14

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 own
  • link() on a directory
  • reboot()
  • Well, link() on a directory isn't normally allowed to root either, but this answer seems good otherwise. – Bruce Fields Jan 17 '17 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.) –  Jan 17 '17 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". – Bruce Fields Jan 18 '17 at 21:22
  • Note that significant portions of the `sockets(7)` subsystem also tend to return `EACCES` when `EPERM` might make more sense (e.g. creating a raw socket, binding a low network port, etc.). I imagine it's a Berkeley-ism. – Kevin Jan 24 '18 at 19:47
  • what is the expansion of EPREM ? – divine Aug 28 '20 at 02:42
0

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."

hidefromkgb
  • 5,834
  • 1
  • 13
  • 44