【发布时间】:2020-04-26 21:32:48
【问题描述】:
我刚刚开始使用模块化编程。
以上是我的两个文件:
你好.c
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk(KERN_ALERT "TEST: Hello world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "TEST: Good Bye");
}
module_init(hello_init);
module_exit(hello_exit);
生成文件
obj-m += hello.o
KDIR = /usr/src/linux-headers-3.13.0-46-generic
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order
这是我的终端输出在 insmod 命令中显示错误,请帮助。
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ make
make -C /usr/src/linux-headers-3.13.0-46-generic SUBDIRS=/home/anubhav/Desktop/os modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
anubhav@anubhav-Inspiron-3421:~/Desktop/os$ insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Operation not permitted
【问题讨论】:
-
@lsowen 我试过“su”和“su -”。但是在提供密码后,我得到了消息“su:身份验证失败”。任何其他前进的方式
-
此消息意味着您输入了错误的密码(或者不是允许成为 root 的用户组的成员)。您需要在
su使用的密码是root密码,而不是您的用户密码。 -
@lsowen ubuntu 网站说,用户可以使用 sudo 命令添加任何需要以 root 身份执行的命令。我的 insmod 命令有效,我使用 dmesg 收到了消息。谢谢。
-
而你没有看到
printk(KERN_ALERT "TEST: Good Bye");因为你还没有完成rmmod hello是吗?
标签: c linux linux-kernel