Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

linux kernel thread

http://hi.baidu.com/j_fo/blog/item/55f4014f1a226937aec3ab01.html
Linux Kernel Thread µÄÌÖÂÛ
2007-05-14 11:45
kernel thread

Gearheads Written by Sreekrishnan Venkateswaran
   Thursday, 15 September 2005

Threads are programming abstractions used in concurrent processing. A kernel thread is a way to implement background tasks
inside the kernel. A background task can be busy handling asynchronous
events or can be asleep, waiting for an event to occur. Kernel threads
are similar to user processes, except that they live in kernel space
and have access to kernel functions and data structures. Like user
processes, kernel threads appear to monopolize the processor because of
preemptive scheduling.
In
this month’s “Gearheads,” let’s discuss kernel threads and develop an
example that also demonstrates such as process states, wait queues, and
user-mode helpers.
Built-in Kernel Threads
To
see the kernel threads (also called kernel processes) running on your
system, run the command ps –ef. You should see something similar to
Figure One.
FIGURE ONE: A typical list of Linux kernel threads
$ ps
–ef
UID       
PID
PPID
C STIME TTY         
TIME CMD
root        
1    
0
0 22:36 ?       
00:00:00 init [3]
root        
2    
1
0 22:36 ?       
00:00:00 [ksoftirqd/0]
root        
3    
1
0 22:36 ?       
00:00:00 [events/0]
root       
38    
3
0 22:36 ?       
00:00:00 [pdflush]
r


Ïà¹ØÎĵµ£º

ºó¼ÌÎÞÈË£ºLinuxºËÐÄά»¤ÈËÔ±ÈÕ½¥²ÔÀÏ

    Ò»ÄêÒ»¶ÈµÄLinux¿ª·¢Õß´ó»áÉÏÖÜÔھɽðɽ¾ÙÐУ¬»áÉÏLinux»ù½ð»áÖ´ÐÐÀíÊÂJim Zemlin±íʾ£¬µÃÒæÓÚÔƼÆËãÒÔ¼°ÆäËü¿Æ¼¼³±Á÷µÄ³öÏÖ£¬LinuxµÄÊг¡µØλʮ·ÖÎȹ̣¬È»¶øһЩÖ÷ÒªµÄά»¤ÈËÔ±ÒѾ­ÈÕ½¥²ÔÀÏ£¬ºó¼ÌÕßÈ´»¹Ã»ÓгÉÊì¡£
   sysfsÄÚºË×Óϵͳά»¤ÕßGrey Kroah-HartmanÖ¸³ö£º“ÉϲãµÄÈËÔ±ÈÔȻà ......

linuxÄÚºËÔ´ÂëÖг£¼ûºê¶¨Òå

1. gccµÄ__attribute__±àÒïÊôÐÔ
ÒªÁ˽âLinux Kernel´úÂëµÄ·Ö¶ÎÐÅÏ¢£¬ÐèÒªÁ˽âÒ»ÏÂgccµÄ__attribute__µÄ±àÒïÊôÐÔ£¬__attribute__Ö÷ÒªÓÃÓڸıäËùÉùÃ÷»ò¶¨ÒåµÄº¯Êý»òÊý¾ÝµÄÌØÐÔ£¬ËüÓкܶà×ÓÏÓÃÓڸıä×÷ÓöÔÏóµÄÌØÐÔ¡£±ÈÈç¶Ôº¯Êý£¬noline½«½ûÖ¹½øÐÐÄÚÁªÀ©Õ¹¡¢noreturn±íʾûÓзµ»ØÖµ¡¢pure±íÃ÷º¯Êý³ý·µ»ØÖµÍ⣬²»»áͨ¹ýÆäËü ......

linuxÆô¶¯¹ý³Ì

linuxÆô¶¯Á÷³Ì£º
ϵͳԤ´¦Àí³ÌÐò->GRUB  (´Ë½×¶Î¿ÉÒÔÀí½âΪbootloader½×¶Î)
->kernel   (´Ë½×¶ÎΪkernel)
->initrd->initÆô¶¯->inittab->rc.sysinit->functions(PATH)->modules->rcX.d(¶ÁÅäÖÃÎļþ)
1.->×Ö·ûģʽ->tty->bash
2.->ͼÐÎģʽ->½øÈëX Window-> ......

LinuxÖÐÕýÈ·´¦Àíerrno

errno±äÁ¿(Ðèinclude errno.h)»á±»¸³Ò»¸öÕûÊýÖµ,²»Í¬µÄÖµ±íʾ²»Í¬µÄº¬Òå,
¿ÉÒÔͨ¹ý²é¿´¸ÃÖµÍƲâ³ö´íµÄÔ­Òò¡£µ«ÊÇerrnoÊÇÒ»¸öÊý×Ö£¬´ú±íµÄ¾ßÌ庬Òå
»¹Òªµ½errno.hÖÐÈ¥ÔĶÁºê¶¨Òå¡£ÓÐÏÂÃ漸ÖÖ·½·¨¿ÉÒÔ·½±ãµÄµÃµ½´íÎóÐÅÏ¢
(Ò»)
#include <stdio.h>
void perror(const char *s)
perror()ÓÃÀ´½«ÉÏÒ»¸öº¯Êý·¢Éú´íÎóµÄ ......

LINUX쵀iptables

Ô­Ìû£ºhttp://www.cnscn.org/read.php?tid-44684.html
iptablesÓÐÈýÖÖÁ´
1£ºINPUT (½øÀ´µÄÁ´)
2£ºOUTPUT(³öÈ¥µÄÁ´)
3£ºFORWARD(ת·¢µÄÁ´)
iptables -A INPUT -p icmp -j DROP
-A(Ìí¼ÓÒ»¸öÁ´) -p ЭÒé -j(Ìí¼Ó¶¯×÷) ˵Ã÷Ìí¼ÓÒ»¸ö½øÀ´µÄÁ´¡£Ð­ÒéÊÇicmp¶¯×÷¾Ü¾ø¡£
iptables -L -n (ÓÃÊ÷ÐνṹÀ´¿´Ò»ÏÂiptablesµÄÉèÖÃ)
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ