access open的区别
access open的区别
摘自Linux Programmer’s Manual中access函数DESCRIPTION节
The check is done using the calling process’s real UID and GID, rather than the effective IDs as is done when
actually attempting an operation (e.g., open(2)) on the file. Similarly, for the root user, the check uses
the set of permitted capabilities rather than the set of effective capabilities; and for non-root users, the
check uses an empty set of capabilities.
可以看到access
系统调用在检测进程对文件的访问权限时,使用的是进程实际用户id和组id。而open
系统调用使用的是有效id,大部分情况下它们的表现没有区别,而若有效id与实际id不同时,则会出现访问权限区别。
APUE书中给了一个例子,略作修改后如下:
1 |
|
在shell中测试它的行为
1 | # 编译完成的后的文件为a.out,目录下存在一个file.txt文件用于测试 |