【发布时间】:2022-01-12 08:51:04
【问题描述】:
使用系统编程创建具有相同时间访问和权限的文件 foo 和 foo2。 我对此一无所知,我不得不在外面创建 foo 和 foo2 ,现在我不确定这是否是正确的方法。 这是我尝试过的:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<string.h>
#include <fcntl.h>
int main()
{
int fd = open("./foo", O_RDWR);
int fd2 = open("./foo2", O_RDWR);
if(fd == -1)
{
printf("\nError creating foo.");
}
else if(fd2 == -1)
{
printf("\nError creating foo2.");
}
else
{
printf("\nFile descripter 1: %d", fd);
printf("\nFile descripter 2: %d", fd2);
}
return 0;
}
【问题讨论】:
-
你可能正在寻找这个:stackoverflow.com/a/42214603/898348
-
“使用系统编程”是指(例如)编写能够理解和修改原始物理磁盘块内容的代码。使用建立在抽象之上的高级 API(然后提供给用户空间)不是系统编程。