易截截图软件、单文件、免安装、纯绿色、仅160KB

linux驱动 自旋锁的运用


linux驱动 自旋锁的运用
//hello.c
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/config.h>
#include <linux/version.h>
#include <asm/uaccess.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <asm/page.h>
#include <linux/poll.h>
#include <linux/kdev_t.h>
#include <asm/semaphore.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
unsigned int test_major = 0;
static int global_var=0;
static int globalvar_count = 0;
char *mystr="wodeshen" ;
static struct semaphore sem;
static spinlock_t spin = SPIN_LOCK_UNLOCKED; //宏定义 已经初始化
static ssize_t read_test(struct file *file,char *buf,size_t count,loff_t *f_pos)
{
int left;
printk(KERN_INFO "read_test\n");
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
return -EFAULT;
if (down_interruptible(&sem))
{
return - ERESTARTSYS;
}
printk("copy_to_user======2=======\n");
copy_to_user(buf, mystr, strlen(mystr));
/*
for(left = count ; left > 0 ; left--)
{
__put_user('1',buf);
buf++;
}
*/
up(&sem);
//return sizeof(int);
return  strlen(mystr);
}
static ssize_t write_test(struct file *file, const char *buf, size_t count, loff_t *f_pos)
{
if (down_interruptible(&sem))
{
return - ERESTARTSYS;
}
if (copy_from_user(&global_var, buf, sizeof(int)))
{
up(&sem);
return - EFAULT;
}
up(&sem);
printk(KERN_INFO "write_test\n");
return sizeof(int);
}
static int open_test(struct inode *inode,struct file *file )
{
spin_lock(&spin);
printk("globalvar open\n");
//临界资源访问
if (globalvar_count)
{
spin_unlock(&spin);
return - EBUSY;
}
globalvar_count++;
//释放自


相关文档:

Linux下设置最大打开文件数

命令行级别 命令行中敲入 ulimit -n 12345 用户级别 编辑/etc/security/limits.conf: 文件,插入一行:userx hard nofile 12345 系统级别 在/etc/sysctl.conf文件中加入一行 fs.file-max=12345,然后在命令行中输入:sysctl -p ,使其生效 ......

Linux 监控/SNMP配置

http://www.zhetao.com/content.dep?m=news&id=1235137892661247
 发布日期 2009-2-20 21:51:32
Linux
系统的
SNMP
服务设置
1)
安装
SNMP
略,请参阅
LINUX
系统
SNMP
安装说明,一般情况下
Linux
中的均已经自动安装了
SNMP
服务。以下命令可以检测
SNMP
服务是否安装以及安装的文件包。
[ ......

linux访问ntfs分区

 
下载ntfs-3g
http://www.ntfs-3g.org/
ntfs-3g依赖FUSE(Filesystem in Userspace)
先处理依赖
下载FUSE
http://fuse.sourceforge.net/
编译FUSE
> ./configure
> make
> make install
编译ntfs-3g
vi 解压后的目录/src/secaudit.c
查找#include <attr/xattr.h>
替换为#include <l ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号