LInux¶àÏ̱߳à³Ì¼¼Êõ×ܽá
Linux¶àÏ̱߳à³Ì¼¼Êõ×ܽá
1
¡¢Ï̵߳Ĵ´½¨¡¢ÖÕÖ¹¼°¿ØÖÆ£º
Èκνø³ÌÔÚÆô¶¯Ê±¾ÍÒÑÓÐÁËÒ»¸öÖ÷Ị̈߳¬Èç¹ûÐèÒªÔÙÉú³ÉÏß³ÌÔòʹÓÃ
pthread_create
º¯Êý£¬Ôڸú¯ÊýÖпÉÒÔÖ¸¶¨Ï̵߳ÄÊôÐÔ¡¢Ïß³ÌÀý³Ì¡¢´«¸øÏß³ÌÀý³ÌµÄ²ÎÊý¡£Ïß³ÌÀý³ÌÊÇÒ»¸öÓû§×Ô¶¨ÒåµÄº¯Êý£¬¼°Ïß³ÌÖ´ÐеĴúÂë¡£µ±Ïß³ÌÀý³Ì·µ»Øʱ£¬Ïß³ÌÔò½áÊøÔËÐУ¬Ò²¿ÉÒÔÏÔʾµ÷ÓÃ
pthread_exit
À´Í˳ö¡£Ïß³ÌÔÚ´´½¨ºó¿ÉÒÔÓÃ
pthread_self
º¯Êý»ñÈ¡Ïß³Ì
ID
¡£º¯Êý
pthread_join
ʹµÃ½ø³ÌµÈ´ýÏ̵߳ÄÖÕÖ¹£¬µ÷ÓÃ
pthread_join
ºó½ø³Ì½«±»¹ÒÆð£¬Ö±µ½Ö¸¶¨µÄij¸öỊ̈߳¨ÔÚ
pthread_join
µÄ²ÎÊý
thread
ÖÐÖ¸¶¨£©ÖÕÖ¹¡£¶ø
pthread_detach
º¯ÊýÕýºÃÏà·´£¬ËüʹµÃ½ø³Ì²»±ØµÈ´ýÏ̵߳ĽáÊø£¬´Ó¶øÔÊÐí½ø³Ì¼ÌÐøÖ´ÐбðµÄ²Ù×÷£¬±»
detach
µÄÏß³ÌÔÚÖ´ÐнáÊøºóÆäÕ¼ÓõÄ×ÊÔ´ÓÉϵͳ×Ô¶¯Êջء£
2
¡¢Ï̼߳äµÄ»¥³â£º
»¥³â²Ù×÷
£¬¾ÍÊǶÔij¶Î´úÂë»òij¸ö±äÁ¿Ð޸ĵÄʱºòÖ»ÄÜÓÐÒ»¸öÏß³ÌÔÚÖ´ÐÐÕâ¶Î´úÂ룬ÆäËûÏ̲߳»ÄÜͬʱ½øÈëÕâ¶Î´úÂë»òͬʱÐ޸ıäÁ¿¡£
pthread
³£ÓÃ
pthread_mutex
»¥³âÌåÀ´ÊµÏÖÏ̻߳¥³â²Ù×÷¡£
pthread_mutex_init
º¯ÊýÓÃÓÚ³õʼ»¯Ò»¸ö»¥³âÌå±äÁ¿¡£
pthread_mutex_lock
º¯ÊýÓÃÓÚ¸ø»¥³âÌå±äÁ¿ÉÏËø£¬Èç¹ûÉÏËøʱ»¥³âÌåÒѾ±»±»µÄÏß³ÌËøסÁË£¬ÄÇôµ÷Óøú¯ÊýµÄÏ߳̽«±»×èÈûÖ±µ½»¥³âÌå±»½âËøΪֹ¡£¶ø
pthread_mutex_trylock
ÔòÊÇÊÔͼËøס»¥³âÌ壬µ«ÔÚ»¥³âÌåÒѾ±»¼ÓËøʱ²»»áÔì³É×èÈû£¬¶øÊÇѸËÙ·µ»Ø¡£
pthread_mutex_unlock
º¯Êý¶Ô»¥³âÌå½âËø¡£
pthread_mutex_destroy
ÔòÓÃÀ´ÊÍ·Å»¥³âÌåËùÕ¼×ÊÔ´¡£
3
¡¢Ï̵߳Äͬ²½£º
ͬ²½¾ÍÊÇÈô¸É¸öÏ̵߳ȴýij¸öʼþµÄ·¢Éú£¬µ±¸Ãʼþ·¢Éúʱ£¬Ò»Æð¿ªÊ¼¼ÌÐøÖ´ÐС£ÔÚ
Linux
Ïß³ÌÖÐÓÃÌõ¼þ±äÁ¿À´ÊµÏÖͬ²½¡£º¯Êý
pthread_cond_init
ÓÃÀ´´´½¨Ò»¸öÌõ¼þ±äÁ¿¡£
pthread_cond_wait
ºÍ
pthread_cond_timewait
ÓÃÀ´µÈ´ýÌõ¼þ±äÁ¿±»ÉèÖã¬ÖµµÃ×¢ÒâµÄÊÇÕâÁ½¸öµÈ´ýµ÷ÓÃÐèÒªÒ»¸öÒѾÉÏËøµÄ»¥³âÌå
mutex
£¬ÕâÊÇΪÁË·ÀÖ¹ÔÚÕæÕý½øÈëµÈ´ý״̬֮ǰ±ðµÄÏß³ÌÓпÉÄÜÉèÖøÃÌõ¼þ±äÁ¿¶ø²úÉú¾ºÕù¡£
pthread_cond_broadcast
ÓÃÓÚÉèÖÃÌõ¼þ±äÁ¿£¬¼´Ê¹Ê¼þ·¢Éú£¬²¢Ê¹µÃËùÓеȴý¸ÃʼþµÄÏ̲߳»ÔÙ×èÈû¡£¶ø
pthread_cond_signal
ÔòÊÇÓýâ³ýijһ¸öµÈ´ýÏ̵߳Ä×èÈû״̬¡£
pthread_cond_destroy
ÓÃÀ´ÊÍ·ÅÒ»¸öÌõ¼þ±äÁ¿µÄ×ÊÔ´¡£
4
¡¢Éú²úÕß——Ïû·ÑÕ
Ïà¹ØÎĵµ£º
·½·¨Ò»£º Expect ʵÏÖ½»»¥
UNIX ´°¿ÚÖÐ ÊäÈëÒÔÏÂÃüÁ
expect ftplinux.txt 10.0.15.22 ftplinux.txt
ftplinux.txt ÖÐÄÚÈÝÈçÏ£º
--¿ªÊ¼-----
spawn ftp [lindex $argv 0]
expect "Name(*):"
send "ftp\r"
expect "Password:*"
send "hell05a\r"
expect "ftp> ......
Name
hosts - The static table lookup for host names
Synopsis
/etc/hosts
Description
This manual page describes the format of the /etc/hosts
file. This file is a simple text file that
associates IP addresses with hostnames, one line per IP address. For
each host a single line should be presen ......
×î½ü¶ÔLinuxµÄÏ߳̽ӿڽøÐÐÁËЩ×ܽᣬҲ²Î¿¼ÁËÍøÂçÉÏÐÖµÜÃǵÄһЩ×ÊÁÏ£¬×Ô¼ºÍ¬Ê±Ò²Ð´ÁËЩ³ÌÐò½øÐвâÊÔ£¬ÏȰѲο¼µÄ
×ÊÁÏÁгöÀ´°É
http://blog.mcuol.com/User/liuzhilii521/Article/12738_1.htm
ÏÂÃæÊÇÎÒµÄһЩÀí½â£º
pthread_key_create(pthread_key_t *key,void (*destructor)(void*))
destructorÕâ¸ö»Øµ÷º¯ÊýÔÚÏß³Ì ......
Linux»ñÈ¡ºÁÃ뼶ʱ¼ä
Moakap
ÔÚÈí¼þÉè¼ÆÖо³£»áÓõ½¹ØÓÚʱ¼äµÄ´¦Àí£¬ÓÃÀ´¼ÆËãÓï¾ä¡¢º¯ÊýµÄÖ´ÐÐʱ¼ä£¬Õâʱ¾ÍÐèÒª¾«È·µ½ºÁÃëÉõÖÁÊÇ΢ÃîµÄʱ¼ä¡£
int gettimeofday(struct
timeval *tv, struct timezone *tz);
int settimeofday(const
struct timeval *tv , const struct timezone *tz);
struc ......