linux - 打开设备失败

标签 linux kernel-module device-node

我正在尝试写入/dev/simulator 文件。 我使用以下方法创建了此设备:

  • # mknod /dev/simulator c 60 0
  • # chmod 666 /dev/simulator
  • # ls -l /dev/simulator
  • crw-rw-rw- 1 root root 60, 0 2012-05-22 19:22 /dev/simulator

我试图打开这个设备并在上面写一些东西,但出现错误:

application: Simulator opening failed

条件是我定义的,为什么我进不了设备? 这是我的代码:

/*
* Some Other Code *
*/

static int simDev;
simDev = open("/dev/simulator", O_RDWR);
if(simDev<0) {
 printf("application: Simulator opening failed.\n");
 exit (1);
}
else 
 printf("Device opened successfully.");

signal(SIGIO, signal_handler);
pid_t pid;
pid = getpid();
write(simDev, &pid, 4);

/*
* Some Other Code *
*/

close(simDev);

谁能帮我改正我的错误?

最佳答案

您没有定义该设备另一端的内核模块。

关于linux - 打开设备失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10713956/

相关文章:

sd卡的linux设备节点作为mmcblk访问CSD寄存器

linux - 使 GNU ld 或 GNU gold 显示存档中使用了哪些 .o 文件

linux - DNSMasq 中的多个 addn-hosts conf

linux - Ubuntu - .ssh 文件夹存在但我看不到它?只能通过终端

linux - 这个 bash 脚本如何启动程序?

linux - 将 bash 命令发送到系统的模块

Android 和内核模块

linux - 如何在 Gentoo Linux 中自动加载内核模块?