#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
int main(){
int fd;
umask(044); //屏蔽权限为044
fd=creat("f4",0666);//赋予权限为666
return 0;
}
执行结果:
-rw--w--w-. 1 root root 0 3月 20 12:54 f4
实际权限为 rw--w--w- 622
赋予权限-屏蔽权限=实际权限
该博客主要介绍了在Linux环境下,通过umask命令设置文件创建时的默认权限,以及如何使用creat系统调用赋予文件特定权限。通过示例代码展示了如何创建一个文件f4,并解释了实际权限是如何通过赋予权限和屏蔽权限计算得出的。

843

被折叠的 条评论
为什么被折叠?



