如何在一个程序中挂载(insmod)一个模块(.ko)

lk0098 2014-08-14 11:11:44
现在我手头有一个hello.ko模块,我需要在另外一个程序A启动的时候把这个模块挂载进内核。使用insmod hello.ko挂载是没有问题的。但是怎么在A启动的时候自动就将hello.ko挂载了呢?具体代码怎么实现?谢谢!
...全文
909 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
懒洋 2014-08-18
  • 打赏
  • 举报
回复
引用 11 楼 lk0098 的回复:
[quote=引用 9 楼 u013296398 的回复:] 直接system()不可以吗??不想这样的话可以单独写一个shell脚本实时检测A有没有启动,不过这样好像比较耗资源
请教一下,如何测试一个.ko模块有没有被挂载?[/quote] :::::lsmod
  • 打赏
  • 举报
回复
probemod可以解决依赖模块关系
  • 打赏
  • 举报
回复
引用 2 楼 lk0098 的回复:
[quote=引用 1 楼 micropentium6 的回复:] write a bash wrapper for A, insmod first and then fire up A. You will have to run it with root.
请教一下bash wrapper是什么?是bash脚本吗? A和那个内核模块式没有关系的,没有启动先后的问题,有没有办法通过编写A的代码启动内核模块?[/quote] So, after all, u still want to load ur module in ur program, do u? <linux/module.h> init_module delete_module Good luck!
lk0098 2014-08-15
  • 打赏
  • 举报
回复
引用 9 楼 u013296398 的回复:
直接system()不可以吗??不想这样的话可以单独写一个shell脚本实时检测A有没有启动,不过这样好像比较耗资源
请教一下,如何测试一个.ko模块有没有被挂载?
  • 打赏
  • 举报
回复
[quote=引用 7 楼 obanaganastar 的回复:] $>modprobe hello.ko
懒洋 2014-08-15
  • 打赏
  • 举报
回复
直接system()不可以吗??不想这样的话可以单独写一个shell脚本实时检测A有没有启动,不过这样好像比较耗资源
刘杰克 2014-08-15
  • 打赏
  • 举报
回复
system(“insmod .ko”)不行吗?
  • 打赏
  • 举报
回复
引用 6 楼 obanaganastar 的回复:
[quote=引用 5 楼 lk0098 的回复:] [quote=引用 4 楼 obanaganastar 的回复:] probemod可以解决依赖模块关系
逗我呢?是modprobe吧。。。 我想不用shell直接在程序里面实现[/quote] 比如: A模块定义个函数 void a_print(int) { .... } EXPORT_SYMBOL(a_print); hello模块 extern void a_print(int); $>modprobe A.ko 加载hello.ko把依赖A.ko一起安装 刚才说错了
  • 打赏
  • 举报
回复
引用 5 楼 lk0098 的回复:
[quote=引用 4 楼 obanaganastar 的回复:] probemod可以解决依赖模块关系
逗我呢?是modprobe吧。。。 我想不用shell直接在程序里面实现[/quote] 比如: A模块定义个函数 void a_print(int) { .... } EXPORT_SYMBOL(a_print); hello模块 extern void a_print(int); $>modprobe A.ko 加载A.ko把依赖hello.ko一起安装
lk0098 2014-08-15
  • 打赏
  • 举报
回复
引用 4 楼 obanaganastar 的回复:
probemod可以解决依赖模块关系
逗我呢?是modprobe吧。。。 我想不用shell直接在程序里面实现
  • 打赏
  • 举报
回复
write a bash wrapper for A, insmod first and then fire up A. You will have to run it with root.
  • 打赏
  • 举报
回复
引用 2 楼 lk0098 的回复:
[quote=引用 1 楼 micropentium6 的回复:] write a bash wrapper for A, insmod first and then fire up A. You will have to run it with root.
请教一下bash wrapper是什么?是bash脚本吗? A和那个内核模块式没有关系的,没有启动先后的问题,有没有办法通过编写A的代码启动内核模块?[/quote] doe your kernel module require rebooting the OS?
lk0098 2014-08-14
  • 打赏
  • 举报
回复
引用 1 楼 micropentium6 的回复:
write a bash wrapper for A, insmod first and then fire up A. You will have to run it with root.
请教一下bash wrapper是什么?是bash脚本吗? A和那个内核模块式没有关系的,没有启动先后的问题,有没有办法通过编写A的代码启动内核模块?

1,324

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧