Ai
146 Star 1.4K Fork 721

LMOS/极客时间-操作系统实战45讲

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.c 640 Bytes
一键复制 编辑 原始数据 按行查看 历史
LMOS 提交于 2021-07-15 20:59 +08:00 . 更新31课代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DEV_NAME "/dev/devicesinfo"
int main(void)
{
char buf[] = {0, 0, 0, 0};
int i = 0;
int fd;
//打开设备文件 O_RDWR, O_RDONLY, O_WRONLY,
fd = open(DEV_NAME, O_RDWR);
if (fd < 0)
{
printf("打开 :%s 失败!\n", DEV_NAME);
}
//写数据到内核空间
write(fd, buf, 4);
//从内核空间中读取数据
read(fd, buf, 4);
//关闭设备 可以不调用,程序关闭时系统自动调用
close(fd);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/lmos/cosmos.git
git@gitee.com:lmos/cosmos.git
lmos
cosmos
极客时间-操作系统实战45讲
master

搜索帮助