亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪(fǎng)問(wèn)板塊 發(fā)新帖
查看: 1190 | 回復(fù): 2
打印 上一主題 下一主題

[內(nèi)核模塊] 用戶(hù)空間跟內(nèi)核空間溝通問(wèn)題 [復(fù)制鏈接]

論壇徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:49:03
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2016-03-16 21:30 |只看該作者 |倒序?yàn)g覽
本帖最后由 shihyu 于 2016-03-16 21:50 編輯

我代碼作用是想從 用戶(hù)空間 appln  process 透過(guò) ioctl  傳 用戶(hù)空間 process 的 pid 到 內(nèi)核 , 內(nèi)核再透過(guò) send_sig 函數(shù)不斷發(fā) SIGUSR2 給用戶(hù)空間的  appln prcoess , 當(dāng)我不想kernel 再發(fā)  SIGUSR2 signal 我再透過(guò) ioctl 讓 kernel 停止發(fā) SIGUSR2
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/device.h>
  5. #include <linux/kernel.h>
  6. #include <linux/oom.h>
  7. #include <linux/sched.h>
  8. #include <linux/delay.h>
  9. #include <linux/kthread.h>
  10. #include "header.h"

  11. MODULE_LICENSE("Dual BSD/GPL");

  12. static int major_no;
  13. static int vrmonitor_pid;
  14. static int cccc = 100;
  15. static int send_sig_flag = 1;

  16. static struct task_struct* brook_tsk;
  17. static int vrmonitor_sig_handler(void* arg);

  18. static int vrmonitor_sig_handler(void* arg)
  19. {
  20.     struct task_struct* p;
  21.     struct pid* pp;

  22.     printk(KERN_EMERG "cccc addr=%p ,cccc=%d\n", &cccc, cccc++);

  23.     pp = find_vpid(vrmonitor_pid);
  24.     p = pid_task(pp, PIDTYPE_PID);

  25.     while (send_sig_flag) {
  26.         msleep(1000);
  27.         send_sig(SIGUSR2, p, 0);
  28.         printk(KERN_EMERG "vrmonitor_sig_handler current pid=%d send to PID=%d \n", current->pid, vrmonitor_pid);
  29.     }

  30.     send_sig_flag = 1;

  31.     return 0;
  32. }

  33. static int device_open(struct inode* inode, struct file* file)
  34. {
  35.     printk(KERN_EMERG "pid=%d, Node Opened\n", current->pid);
  36.     return 0;
  37. }

  38. int device_ioctl(struct file* filp,
  39.                  unsigned int cmd,
  40.                  unsigned long args)
  41. {
  42.     int ret;

  43.     switch (cmd) {
  44.     case IOCTL_CMD:
  45.         printk(KERN_EMERG "IOCTL_CMD");
  46.         break;

  47.     case IOCTL_SEND_PID:
  48.         printk(KERN_EMERG "appln PID=%u , current kernel pid=%d\n", (unsigned int)args, current->pid);
  49.         vrmonitor_pid = (unsigned int)args;
  50.         brook_tsk = kthread_create(vrmonitor_sig_handler, NULL, "brook");

  51.         if (IS_ERR(brook_tsk)) {
  52.             ret = PTR_ERR(brook_tsk);
  53.             brook_tsk = NULL;
  54.             goto out;
  55.         }

  56.         wake_up_process(brook_tsk);
  57.         break;

  58.     case IOCTL_STOP_SIG:
  59.         send_sig_flag = 0;
  60.         printk(KERN_EMERG "IOCTL_STOP_SIG send_sig_flag=%d\n", send_sig_flag);
  61.         break;

  62.     default:
  63.         printk(KERN_EMERG "Illegal ioctl command word\n");
  64.         break;
  65.     }

  66.     return 0;

  67. out:
  68.     return ret;
  69. }

  70. static int device_release(struct inode* inode, struct file* file)
  71. {
  72.     printk(KERN_EMERG "Module Released \n");
  73.     return 0;
  74. }

  75. static struct class* my_class;

  76. static struct file_operations fops = {
  77.     .open = device_open,
  78.     .release = device_release,
  79.     .unlocked_ioctl = device_ioctl
  80. };

  81. static int hello_init(void)
  82. {
  83.     major_no = register_chrdev(0, DEVICE_NAME, &fops);
  84.     printk(KERN_EMERG "Module Major No : %d\n", major_no);

  85.     my_class = class_create(THIS_MODULE, DEVICE_NAME);
  86.     device_create(my_class, NULL, MKDEV(major_no, 0), NULL, DEVICE_NAME);
  87.     printk(KERN_EMERG "Module loaded in kernel\n");
  88.     return 0;
  89. }

  90. static void hello_exit(void)
  91. {
  92.     printk(KERN_EMERG "Device is Released or closed \n");
  93.     device_destroy(my_class, MKDEV(major_no, 0));
  94.     class_unregister(my_class);
  95.     class_destroy(my_class);
  96.     unregister_chrdev(major_no, DEVICE_NAME);
  97. }

  98. module_init(hello_init);
  99. module_exit(hello_exit);
復(fù)制代碼
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <sys/ioctl.h>
  7. #include <signal.h>
  8. #include "header.h"

  9. static int fd;

  10. void stop_sig(int sig)
  11. {
  12.     unsigned int sig_flag = 0;

  13.     ioctl(fd, IOCTL_STOP_SIG, sig_flag);
  14.     printf("stop_sig=%d, pid=%d\n", sig, getpid());
  15.     (void) signal(SIGINT, SIG_DFL);

  16. #if 0
  17.     kill(getpid(), SIGINT);
  18. #endif
  19. }


  20. void signal_handler(int signum)
  21. {
  22.     printf("signal_handler %d, pid=%d\n", signum, getpid());

  23.     if (signum == SIGUSR2) {
  24.         printf("SIGUSR2\n");
  25.     } else if (signum == SIGUSR1) {
  26.         printf("SIGUSR1\n");
  27.     }
  28. }

  29. int main()
  30. {
  31.     pid_t pid = getpid();

  32.     printf("PID=%u\n", pid);

  33.     signal(SIGUSR2, signal_handler);
  34.     signal(SIGINT, stop_sig);

  35.     fd = open(DEVICE_PATH, O_RDWR);
  36.     if (fd == -1) {
  37.         printf("open fail\n");
  38.         exit(-1);
  39.     }

  40.     ioctl(fd, IOCTL_SEND_PID, pid);
  41.     printf("Ioctl executed\n");

  42.     while(1) {}

  43.     close(fd);
  44.     return 0;
  45. }
復(fù)制代碼
運(yùn)行步驟
sudo insmod sample.ko
sudo ./appln


下面是打印出來(lái)的log


// user space log
PID=6897
Ioctl executed
signal_handler 12, pid=6897
SIGUSR2
signal_handler 12, pid=6897
SIGUSR2
^Cstop_sig=2, pid=6897  // ctrl + c 發(fā)往 kernel 讓kernel停止發(fā)送 SIGUSR2


// kernel log
[  681.335568] vrmonitor_sig_handler current pid=6898 send to PID=6897
[  682.339540] vrmonitor_sig_handler current pid=6898 send to PID=6897
[  682.871588] IOCTL_STOP_SIG send_sig_flag=0  // kernel 收到準(zhǔn)備停止
[  682.871646] Module Released
[  683.343531] vrmonitor_sig_handler current pid=6898 send to PID=6897



我再一般pc上運(yùn)行正常 ,


可是再 vmware  ubuntu kernel 只發(fā)兩次 SIGUSR2 , 就打印出 Module Released
下面 log ,  user space 的 appln  prcoess 就莫名其妙結(jié)束 , 我還沒(méi)按 ctrl+c
只是啟動(dòng) sudo ./appln 這樣




[  681.335568] vrmonitor_sig_handler current pid=6898 send to PID=6897
[  682.339540] vrmonitor_sig_handler current pid=6898 send to PID=6897
[  682.871646] Module Released

example.tar.bz2

47.81 KB, 下載次數(shù): 1

8987

論壇徽章:
9
辰龍
日期:2014-08-18 20:38:42未羊
日期:2014-09-04 08:50:45丑牛
日期:2014-09-06 00:12:55寅虎
日期:2014-12-22 20:50:56摩羯座
日期:2015-01-14 22:28:15巳蛇
日期:2015-01-23 20:39:272015年辭舊歲徽章
日期:2015-03-03 16:54:1515-16賽季CBA聯(lián)賽之青島
日期:2016-03-13 23:37:1915-16賽季CBA聯(lián)賽之深圳
日期:2016-03-29 18:52:38
2 [報(bào)告]
發(fā)表于 2016-03-17 00:52 |只看該作者
收到另的信號(hào)退出了呀。GDB一個(gè)就知道了呀。或者unlimit -c unlimited,產(chǎn)生個(gè)core文件看看

論壇徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:49:03
3 [報(bào)告]
發(fā)表于 2016-03-17 01:29 |只看該作者
本帖最后由 shihyu 于 2016-03-17 01:29 編輯

ok... 我明天試試看 gdb
thanks
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP