问题
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.
回答1:
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()
回答2:
According to Linux programmers, learn the difference between EACCES and EPERM already! - A Random Dev's Rants...
EACCES
"Permission denied" should be used to mean that the user doesn't have sufficient privileges to do the action. The root user, or another user with sufficient user/group permissions should be able to do the action.EPERM
"Operation not permitted" should be used to mean the action is not possible or safe in general, regardless of whether the user is root or not. Examples would be:chmod
ing a file on a FAT filesystem (the filesystem doesn't support permission bits)
- Note that a lot of Linux code returns
EPERM
when it should really returnEACCES
.
回答3:
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."
来源:https://stackoverflow.com/questions/35023667/difference-between-eacces-and-eperm