一个奇怪的不可中断进程
来源:互联网 发布:mac怎么共享 编辑:程序博客网 时间:2024/06/07 06:25
写了个简单的驱动,以及应用层的读写程序。优先卸载了驱动,然后...应用程序卡在那里了,任凭你怎么kill,怎么重新装载驱动,都没有反应。。。
/** * @file global_var.c * @author wzj * @brief competation * @version 1.1 * @note * @date: 2012年08月02日星期四23:39:28 * */ #include <linux/module.h>#include <linux/init.h>#include <linux/fs.h>#include <asm/uaccess.h>#include <linux/semaphore.h>#include <linux/spinlock.h>MODULE_LICENSE("GPL");#define MAJOR_NUM(239)static ssize_t global_var_read(struct file*, char*, size_t, loff_t *);static ssize_t global_var_write(struct file*, const char*, size_t, loff_t *);static int global_var_open(struct inode *inode, struct file *filp);static int global_var_release(struct inode *inode, struct file *filp);struct file_operations globalvar_fops ={read:global_var_read,write:global_var_write,open:global_var_open,release:global_var_release,};static int global_var = 0;static struct semaphore sem;static int globalvar_count = 0;static spinlock_t spin = SPIN_LOCK_UNLOCKED;static int __init globalvar_init(void){int ret;ret = register_chrdev(MAJOR_NUM, "globalvar", &globalvar_fops);if(ret){printk("register failed.");} else {printk("register success");init_MUTEX(&sem);}return ret;}static void __exit globalvar_exit(void){int ret;unregister_chrdev(MAJOR_NUM, "globalvar");if(ret){printk("globalvar unregister failed");} else {printk("globalvar unregister_chrdev oK");}}static ssize_t global_var_read(struct file *filp, char *buf, size_t len,loff_t *off){/* get semaphore */if(down_interruptible(&sem)) //这个明明是可以中断的..为什么最后卡在这里了?{return -ERESTARTSYS;}if(copy_to_user(buf, &global_var, sizeof(int))){up(&sem);return -EFAULT;}up(&sem);return sizeof(int);}static ssize_t global_var_write(struct file *filp, const char *buf, size_t len, loff_t *off){if(down_interruptible(&sem)){return -ERESTARTSYS;}if(copy_from_user(&global_var, buf, sizeof(int))){up(&sem);return -EFAULT;}up(&sem);return sizeof(int);}static int global_var_open(struct inode *inode, struct file *filp){spin_lock(&spin);if(globalvar_count){spin_unlock(&spin);return -EBUSY;}globalvar_count++;spin_unlock(&spin);return 0;}static int global_var_release(struct inode *inode, struct file *filp) {spin_lock(&spin);globalvar_count--;spin_unlock(&spin);return 0;}module_init(globalvar_init);module_exit(globalvar_exit);
下面的应用程序,一直在读取上面那个驱动的内容,down_interruptible()明明是可以中断的,进程为什么在驱动卸载后变成不可中断的,并卡在那里了?
/** * \file vartest.c * \author wzj * \brief * \version * \note * \date: 2012年08月06日星期一22:58:04 * * discript your detail info. */ #include <stdio.h>#include <unistd.h>int main(){FILE *fp = fopen("/dev/globalvar", "r");if(fp == NULL){printf("open failed...\n");return -1;}while(1){int val = 0;read(fileno(fp), &val, sizeof(val));printf("%d\n", val);sleep(3);}fclose(fp);return 0;}
- 一个奇怪的不可中断进程
- linux僵尸进程&&进程进入不可中断休眠状态
- 一个奇怪的问题
- 一个奇怪的程式
- 一个奇怪的故障
- 一个奇怪的表达式
- 一个奇怪的bug
- 一个奇怪的问题
- 一个奇怪的问题
- 一个奇怪的问题
- 一个奇怪的listview
- 一个奇怪的bug
- 一个奇怪的Exception
- 一个奇怪的国家
- 奇怪的进程: *.vshost.exe
- delphi编写搜索进程函数的一个奇怪的现象(已解决)
- Java 处理不可中断的阻塞
- 中断不可睡眠的一些理解
- asp.net中获取当前url的方法
- hibernate拦截器的用途之一
- Drupal当中的entity node之间的关系
- 交易员学堂第七课 如何对待交易秘籍?
- xml
- 一个奇怪的不可中断进程
- 修改exe
- spring学习
- Proactor和Reactor模式
- POJ 1580 String Matching 很纠结,代码写了很多,还是过了,再对比一下人家的代码,惭愧
- 黑马程序员——JAVA(JDBC)
- [FI] SAP 关于标准成本、计划成本、目标成本、实际成本
- Luence认识1
- 毕业小记