Chinaunix首页 | 论坛 | 博客
  • 博客访问: 37086
  • 博文数量: 8
  • 博客积分: 476
  • 博客等级: 下士
  • 技术积分: 145
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-11 15:53
文章分类
文章存档

2012年(1)

2011年(5)

2010年(2)

我的朋友

分类: LINUX

2011-08-29 10:32:18

1:在写一个内核线程时如果用kernel_thread创建要在添加daemonize("name"),让这个进程给0号进程进行管理。
例如:
         kernel_thread(hello,3,CLONE_FS | CLONE_FILES | CLONE_SIGHAND);

 void hello(int num)
{
daemonize("hello");
while(num>0){
........
}
}

2:在写一个带有while函数,切记要注意经给这个函数退出的条件。若不然这个wile函数会一直占用资源。
例:
         void hello(int num)
{
whlie(1){

...
...
}
}
这样的函数在退出时不能释放资源,不应该这样呀。至少要加个判断有机会退出while循环。
如在while(1){
if(num<0){
   break;
}
     }

3:在内核空间调用各户空间的应用程序call_usermodehelper

NAME
call_usermodehelper - start a usermode application  
SYNOPSIS

int call_usermodehelper  (char * path, char ** argv, char ** envp, int wait);

 
ARGUMENTS

path
pathname for the application

argv
null-terminated argument list

envp
null-terminated environment list

wait
wait for the application to finish and return status.

 
DESCRIPTION

Runs a user-space application. The application is started asynchronously if wait is not set, and runs as a child of keventd. (ie. it runs with full root capabilities).

Must be called from process context. Returns a negative error code if program was not execed successfully, or 0.

在网上可以找到很多它的用法,其实我想说的时,当内核调用用户空间的程序时,在传递参数最好是把绝对路径加上。因为发现其实是把用户程序拷贝到根目录下运行,如果参数是一些文件的什么的就要用绝对路径,不然会发现调用后没有达到预期的效果。

4  文件流操作

在文件流操作中有几个函数如:

fseek(FILE,offset,whence);

fprintf(FILE,format,str);

fscanf(FILE,format,str);

这三个函数都是把文件指针写在第一个参数。而其他的函数都把文件指针写在参数的最后一个。

fread(str,size,count,FILE);

fwrite(str,size,count,FILE);

fgets(str,count,FILE);

fputs(str,count,FILE);

5 函数的参数传递问题

今天看到一道题



阅读(801) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~