Linux Kernel時序的三種機制
最近在寫Driver時,常常遇到需要「等待一段時間」再處理的動作,以往我都傻傻的用msleep()或mdelay(),殊不知這種busy waiting會hold住cpu資源,在這段期間內都無法讓給其他process執行,時間短(10ms以下等級)或許還可以,太長就不行了,所以需要Kernel本身就有提供的「時序」機制來做處理,於是我漸漸學會了如何使用Timer、Tasklet和Workqueue的用法,在O'Reilly的Linux Device Drivers第七章有詳細的講解,我將書上的精華茲簡單整理如下:
##CONTINUE##
一、Timer
#include <linux/timer.h>
struct timer_list
{
/* ... */
unsigned long expires;//期望運行的 jiffies 值
void (*function)(unsigned long);
unsigned long data;//傳給function的參數
};//使用前必須初始化
void init_timer(struct timer_list *timer);
//初始化一個timer_list
struct timer_list TIMER_INITIALIZER(_function, _expires, _data);
//初始化一個靜態的timer_list
void add_timer(struct timer_list * timer);
int mod_timer(struct timer_list *timer, unsigned long expires);
int del_timer(struct timer_list * timer);
int del_timer_sync(struct timer_list *timer);
//同 del_timer 一樣,但保證函數return時,定時器函數不在任何 CPU 上運行
//避免在SMP 系統上競爭
int timer_pending(const struct timer_list * timer);
//返回真或假來指示是否定時器已被運行
二、Tasklet
#include <linux/interrupt.h>
struct tasklet_struct {
/* ... */
void (*func)(unsigned long);
unsigned long data;
};
void tasklet_init(struct tasklet_struct *t,
void (*func)(unsigned long), unsigned long data);
//將定義好的結構體初始化,才可用
DECLARE_TASKLET(name, func, data);
//直接申明就可用了
DECLARE_TASKLET_DISABLED(name, func, data);
void tasklet_disable(struct
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
RPM有5种基本操作模式(不包括软件包建构):安装、删除、升级、查询和校验。
RPM包的名称格式,eg:caleng-1.0-1.i386.rpm。该文件名包括软件包名称“caleng”;软件版本号“1.0“,其中包括主版本号和次版本号;"i386"是软件所运行的硬件平台。
1、安装RPM包,eg: $>rpm -ivh test.rp ......
linux系统root用户可强制踢制其它登录用户,
首先以root登录以便查看全部的在线用户信息,可用w命令查看登录用户信息
强制踢人命令格式:pkill -kill -t tty
解释:
pkill -kill -t 踢人命令
tty 所踢用户的TTY
如上踢出liu用户的命令为: pkill -kill -t pts/1
......
原文地址:http://www.wangzhongyuan.com/archives/488.html
以下是一个Linux/Unix下由两个管道提供双向数据流的C程序,这是操作系统课程中经常使用的基本程序
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <string.h>
int m ......