4. Threads
To use the POSIX standard thread API (pthreads), link libpthread.so
to your program.
4.1. Thread Creation
Each thread in a process is identified by a thread ID,
pthread_t.
The pthread_self function returns the thread ID of the current
thread.
This thread IDs can be compared with the pthread_equal
function.
if (!pthread_equal (pthread_self (),
other_thread))
pthread_join
(other_thread, NULL);
each thread executes a thread function:
void * function(void *)
The pthread_create function creates a new thread.
A pointer to a pthread_t variable: store the thread ID of
the new thread.
A pointer to a thread attribute object. You can pass NULL
to use the default attributes.
A pointer to the thread function. void* (*) (void*)
A thread argument value of type void*.
Compile and link this program:
% cc -o thread-create thread-create.c
–lpthread
A thread exits in two ways.
return from the thread function. The function return value
i ......
1
¡¢×ܽᱳ¾°
ÔÚ
linux
ϵͳÏ£¬Èç¹ûÄãÏÂÔØ²¢°²×°ÁËÓ¦ÓóÌÐò£¬ºÜÓпÉÄÜÔÚ¼üÈëËüµÄÃû³ÆÊ±³öÏÖ
“command not found”
µÄÌáʾÄÚÈÝ¡£Èç¹ûÿ´Î¶¼µ½°²×°Ä¿±êÎļþ¼ÐÄÚ£¬ÕÒµ½¿ÉÖ´ÐÐÎļþÀ´½øÐвÙ×÷¾ÍÌ«·±ËöÁË¡£ÕâÉæ¼°µ½»·¾³±äÁ¿
PATH
µÄÉèÖÃÎÊÌ⣬¶ø
PATH
µÄÉèÖÃÒ²ÊÇÔÚ
linux
϶¨ÖÆ»·¾³±äÁ¿µÄÒ»¸ö×é³É²¿·Ö¡£±¾°¸Àý»ùÓÚ
RedHat AS4
½²½â»·¾³±äÁ¿¶¨ÖƵÄÎÊÌâ¡£
2
¡¢±äÁ¿¼ò½é
Linux
ÊÇÒ»¸ö¶àÓû§µÄ²Ù×÷ϵͳ
¡£Ã¿¸öÓû§µÇ¼ϵͳºó£¬¶¼»áÓÐÒ»¸öרÓõÄÔËÐл·¾³¡£Í¨³£Ã¿¸öÓû§Ä¬ÈϵĻ·¾³¶¼ÊÇÏàͬµÄ£¬Õâ¸öĬÈÏ»·¾³Êµ¼ÊÉϾÍÊÇÒ»×é»·¾³±äÁ¿µÄ¶¨Òå¡£Óû§¿ÉÒÔ¶Ô×Ô¼ºµÄÔËÐл·¾³½øÐж¨ÖÆ£¬Æä·½·¨¾ÍÊÇÐÞ¸ÄÏàÓ¦µÄϵͳ»·¾³±äÁ¿¡£
3
¡¢¶¨ÖÆ»·¾³±äÁ¿
»·¾³±äÁ¿ÊǺÍ
Shell
½ôÃÜÏà¹ØµÄ£¬Óû§µÇ¼ϵͳºó¾ÍÆô¶¯ÁËÒ»¸ö
Shell
¡£¶ÔÓÚ
Linux
À´ËµÒ»°ãÊÇ
bash
£¬µ«Ò²¿ÉÒÔÖØÐÂÉ趨»òÇл»µ½ÆäËü
µÄ
Shell
£¨Ê¹ÓÃ
chsh
ÃüÁ¡£
¸ù¾Ý·¢Ðа汾µÄÇé¿ö£¬
bash
ÓÐÁ½¸ö»ù±¾µÄϵͳ¼¶ÅäÖÃÎļþ£º
/etc/bashrc
ºÍ
/etc/profile
¡£ÕâЩÅäÖÃÎļþ°üº¬Á½×鲻ͬµÄ±äÁ¿£º
shell
±äÁ¿ºÍ»·¾³±äÁ¿¡£Ç°ÕßÖ»ÊÇÔÚÌØ¶¨µÄ
shell
Öй̶¨£¨Èç
bash
£©£¬ºóÕßÔÚ²»Í¬
shell
Öй̶¨¡£º ......
6. Devices
A device driver hides the hardware device’s communication
protocols from the operating system and allows the system to interact with the
device through a standardized interface.
Processes can communicate with a device driver via
file-like objects.
6.1 Device Types
A character device represents a hardware device that reads
or writes a serial stream of data bytes.
A block device represents a hardware device that reads or
writes data in fixed-size blocks.
6.2 Device Numbers
Linux identifies devices using two numbers: the major
device number and the minor device number.
The major device number specifies which driver the device
corresponds to.
Minor device numbers distinguish individual devices or
components controlled by a single driver.
The special entry /proc/devices lists major device numbers
corresponding to active device drivers currently loaded into the kernel.
[liuchao@localhost ~]$ cat /proc/devices
Character devices:
1
mem
&n ......
apacheµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/apache" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-included-apr" \
"--enable-so" \ #--------------------¿ªÆôÏàÓ¦µÄÀ©Õ¹Ä£¿éÖ§³Ö
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--disable-userdir"
make #--------------------±àÒë
make install #--------------------±àÒë°²×°
phpµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/php" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/php/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-icon ......
apacheµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/apache" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-included-apr" \
"--enable-so" \ #--------------------¿ªÆôÏàÓ¦µÄÀ©Õ¹Ä£¿éÖ§³Ö
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--disable-userdir"
make #--------------------±àÒë
make install #--------------------±àÒë°²×°
phpµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/php" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/php/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-icon ......
apacheµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/apache" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-included-apr" \
"--enable-so" \ #--------------------¿ªÆôÏàÓ¦µÄÀ©Õ¹Ä£¿éÖ§³Ö
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--disable-userdir"
make #--------------------±àÒë
make install #--------------------±àÒë°²×°
phpµÄÔ´Âë°²×°
½«Ñ¹Ëõ°ü½âѹ֮ºó½øÈëÏàÓ¦µÄĿ¼
./configure \ #--------------------Ô¤±àÒëÃüÁî
"--prefix=/usr/local/php" \ #--------------------°²×°Â·¾¶Îª“/usr/local/apache”
"--with-apxs2=/usr/local/apache/bin/apxs" \
"--with-config-file-path=/usr/local/php/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2" \
"--with-gd=/usr/local/gd2" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-icon ......
2008-07-07 22:04×´ ̬¼ì²â(stateful inspection)ÊÇÓÉCheckPoint¹«Ë¾×îÏÈÌá³öµÄ£¬¿ÉËãÊÇ·À»ðǽ¼¼ÊõµÄÒ»ÏîÍ»ÆÆÐÔ±ä¸ï£¬°Ñ°ü¹ýÂ˵ĿìËÙÐԺʹúÀíµÄ°²È«ÐԺܺõؽáºÏÔÚÒ»Æð£¬ ĿǰÒѾÊÇ·À»ðǽ×îÁ÷Ðеļì²â·½Ê½¡£×´Ì¬¼ì²âµÄ¸ù±¾Ë¼ÏëÊǶÔËùÓÐÍøÂçÊý¾Ý½¨Á¢“Á¬½Ó”µÄ¸ÅÄ´Ë“Á¬½Ó”ÊÇÃæÏò“Á¬½Ó”µÄÐÒéÖ®“Á¬½Ó”µÄÀ©Õ¹£¬¶Ô·ÇÁ¬½Ó ÐÒéÊý¾ÝÒ²¿ÉÒÔ½¨Á¢ÐéÄâÁ¬½Ó¡£¼ÈÈ»ÊÇÁ¬½Ó£¬±ØÈ»ÊÇÓÐÒ»¶¨µÄ˳ÐòµÄ£¬Í¨ÐÅÁ½±ßµÄÁ¬½Ó״̬ҲÊÇÓÐÒ»¶¨Ë³Ðò½øÐб仯µÄ¡£·À»ðǽµÄ״̬¼ì²â¾ÍÊÇÊÂÏÈÈ·¶¨ºÃÁ¬½ÓµÄºÏ ·¨¹ý³Ìģʽ£¬Èç¹ûÊý¾Ý¹ý³Ì·ûºÏÕâ¸öģʽ£¬Ôò˵Ã÷Êý¾ÝÊǺϷ¨ÕýÈ·µÄ£¬·ñÔò¾ÍÊÇ·Ç·¨Êý¾Ý£¬Ó¦¸Ã±»¶ªÆú¡£
2.6Äں˵ÄLinuxÖеķÀ»ðǽ´úÂënetfilterÖÐʵÏÖÁË״̬¼ì²â (stateful inspection)¼ì²â¼¼Êõ£ºLinuxΪÿһ¸ö¾¹ýÍøÂç¶ÑÕ»µÄÊý¾Ý°ü£¬Éú³ÉÒ»¸öеÄÁ¬½Ó¼Ç¼ÏConnection entry£©¡£´Ëºó£¬ËùÓÐÊôÓÚ´ËÁ¬½ÓµÄÊý¾Ý°ü¶¼±»Î¨Ò»µØ·ÖÅ䏸Õâ¸öÁ¬½Ó£¬²¢±êʶÁ¬½ÓµÄ״̬¡£linuxÔÚnetfilterµÄhookµãÉÏΪ contrack¶¨ÒåÁËÈçϼ¸¸ö¹Ò½Óµã£¬ÓÃÀ´´¦ÀíÁ÷¾µÄip°ü£º
NF_IP_PRE_ROUTING £º ip_conntrack_defrag -> ip_conntr ......
2008-07-07 22:05
³õʼ»¯
1£¬ip_conntrack_standalone_initÊÇcontrackÄ£¿éµÄ³õʼ»¯º¯Êý¡£ËüÖ÷ÒªÍê³ÉÒÔÏÂÄÚÈÝ£º
/*1, ³õʼ»¯conntrackÏà¹ØµÄÊý¾Ý½á¹¹£¬Èçhash±í£¬ip_conntrack_protocolÒÔ¼°ÄÚ´æ¹ÜÀíµÈ*/
ret = ip_conntrack_init();
if (ret < 0)
return ret;
#ifdef CONFIG_PROC_FS
/* ÔÚ/procĿ¼Ï´´½¨"ip_conntrack"£¬"ip_conntrack_expect"¼Ç¼Á¬½Ó¸ú×ÙÐÅÏ¢*/
……
#endif
/*2£¬Îªconntrack×¢²áhookµã*/
ret = nf_register_hooks(ip_conntrack_ops, ARRAY_SIZE(ip_conntrack_ops));
if (ret < 0) {
printk("ip_conntrack: can't register hooks.\n");
goto cleanup_proc_stat;
}
#ifdef CONFIG_SYSCTL
/*3£¬×¢²ásysctrlµÄ²Ù×÷º¯Êý¼¯*/
ip_ct_sysctl_header = register_sysctl_table(ip_ct_net_table, 0);
if (ip_ct_sysctl_header == NULL) {
printk("ip_conntrack: can't register to sysctl.\n");
ret = -ENOMEM;
goto cleanup_hooks;
}
#endif
......