开启linux 内核线程
函数说明:
kthread_create:创建线程。
struct task_struct *kthread_create(int (*threadfn)(void *data),void *data,const char *namefmt, ...);
线程创建后,不会马上运行,而是需要将kthread_create() 返回的task_struct指针传给wake_up_process(),然后通过此函数运行线程。
kthread_run :创建并启动线程的函数:
struct task_struct *kthread_run(int (*threadfn)(void *data),void *data,const char *namefmt, ...);
kthread_stop:通过发送信号给线程,使之退出。
int kthread_stop(struct task_struct *thread);
线程一旦启动起来后,会一直运行,除非该线程主动调用do_exit函数,或者其他的进程调用kthread_stop函数,结束线程的运行。
但如果线程函数正在处理一个非常重要的任务,它不会被中断的。当然如果线程函数永远不返回并且不检查信号,它将永远都不会停止。
代码:
#include <linux/kthread.h>
#include <linux/module.h>
#ifndef SLEEP_MILLI_SEC
#define SLEEP_MILLI_SEC(nMilliSec)\
do { \
long timeout = (nMilliSec) * HZ / 1000; \
while(timeout > 0) \
{ \
timeout = schedule_timeout(timeout); \
} \
}while(0);
#endif
static struct task_struct * MyThread = NULL;
static int MyPrintk(void *data)
{
char *mydata = kmalloc(strlen(data)+1,GFP_KERNEL);
memset(mydata,'\0',strlen(data)+1);
strncpy(mydata,data,strlen(data));
while(!kthread_should_stop())
{
SLEEP_MILLI_SEC(1000);
printk("%s\n",mydata);
}
kfree(mydata);
return 0;
}
static int __init init_kthread(void)
{
MyThread = kthread_run(MyPrintk,"hello world","mythread");
return 0;
}
static void __exit exit_kthread(void)
{
if(MyThread)
{
printk("stop MyThread\n");
kthread_stop(MyThread);
}
}
module_init(init_kthread);
module_exit(exit_kthread);
MODULE_AUTHOR("YaoGang");
这个内核线程的作用就是每隔一秒打印一个“hello world”。
值得一提的是kthread_should_stop函数,我们需要在开启的线程中嵌入该函数,否则kthread_stop是不起作用的。
相关文档:
Linux支持多种文件系统,包括ext2、ext3、vfat、ntfs、iso9660、jffs、romfs和nfs等,为了对各类文件系统进行统一管理,Linux引入了虚拟文件系统VFS(Virtual File System),为各类文件系统提供一个统一的操作界面和应用编程接口。
Linux下的文件系统结构如下:
Linux启动时, ......
尚学堂linux笔记(二)
touch 文件 创建文件
rm 文件名 删除文件
rm –r 文件夹名 递归删除文件夹
rm –rf 文件夹名 递归强制删除文件夹
rmdir 文件夹名 删除空文件夹
cp (-r)源文件/原文件夹 目标文件/目标文件夹
mv(-r) 源文件 目标文件/目标文件夹
tree 树状显示
查看环境变量:windows ......
I/O重定向详解及应用实例
1、 基本概念(这是理解后面的知识的前提,请务必理解)
a、 I/O重定向通常与 FD有关,shell的FD通常为10个,即 0~9;
b、 常用FD有3个,为0(stdin,标准输入)、1(stdout,标准输出)、2(stderr,标准错误输出),默认与keyboard、monitor、monitor有关;
c、 用 < 来改变读进的 ......
1.启动蓝牙设备
sudo /etc/init.d/bluetooth restart
或者
sudo /etc/init.d/bluez-utils restart
2.使用hcitool dev查看计算机上的蓝牙设备
teapot@teapot:~$ hcitool dev
Devices:
hci0 00:16:CF:DB:B4:BF
teapot@teapot:~$
3.安装设备
查询设备地址
teapot@teapot:~$ sudo hidd - ......
1、Linux下mysql安装完后是默认:区分表名的大小写,不区分列名的大小写;
2、用root帐号登录后,在/etc/my.cnf 中的[mysqld]后添加添加lower_case_table_names=1,重启MYSQL服务,这时已设置成功:不区分表名的大小写;
lower_case_table_names参数详解:
lower_case_table_names = 0
其中 0:区分大小写,1 ......