LinuxÖеÄwaitϵͳµ÷ÓÃ
ϵͳÖеĽ©Ê¬½ø³Ì¶¼ÒªÓÉwaitϵͳµ÷ÓÃÀ´»ØÊÕ£¬ÏÂÃæ¾Íͨ¹ýʵս¿´Ò»¿´waitµÄ¾ßÌåÓ÷¨£º
waitµÄº¯ÊýÔÐÍÊÇ£º
#include <sys/types.h> /* ÌṩÀàÐÍpid_tµÄ¶¨Òå */
#include <sys/wait.h>
pid_t wait(int *status);
½ø³ÌÒ»µ©µ÷ÓÃÁËwait£¬¾ÍÁ¢¼´×èÈû×Ô¼º£¬ÓÉwait×Ô¶¯·ÖÎöÊÇ·ñµ±Ç°½ø³ÌµÄij¸ö×Ó½ø³ÌÒѾÍ˳ö£¬Èç¹ûÈÃËüÕÒµ½ÁËÕâÑùÒ»¸öÒѾ±ä³É½©Ê¬µÄ×Ó½ø³Ì£¬ wait¾Í»áÊÕ¼¯Õâ¸ö×Ó½ø³ÌµÄÐÅÏ¢£¬²¢°ÑËü³¹µ×Ïú»Ùºó·µ»Ø£»Èç¹ûûÓÐÕÒµ½ÕâÑùÒ»¸ö×Ó½ø³Ì£¬wait¾Í»áÒ»Ö±×èÈûÔÚÕâÀֱµ½ÓÐÒ»¸ö³öÏÖΪֹ¡£
²ÎÊýstatusÓÃÀ´±£´æ±»ÊÕ¼¯½ø³ÌÍ˳öʱµÄһЩ״̬£¬ËüÊÇÒ»¸öÖ¸ÏòintÀàÐ͵ÄÖ¸Õë¡£µ«Èç¹ûÎÒÃǶÔÕâ¸ö×Ó½ø³ÌÊÇÈçºÎËÀµôµÄºÁ²»ÔÚÒ⣬ֻÏë°ÑÕâ¸ö½©Ê¬½ø³ÌÏûÃðµô£¬£¨ÊÂʵÉϾø´ó¶àÊýÇé¿öÏ£¬ÎÒÃǶ¼»áÕâÑùÏ룩£¬ÎÒÃǾͿÉÒÔÉ趨Õâ¸ö²ÎÊýΪNULL£¬¾ÍÏóÏÂÃæÕâÑù£º
pid = wait(NULL);
Èç¹û³É¹¦£¬wait»á·µ»Ø±»ÊÕ¼¯µÄ×Ó½ø³ÌµÄ½ø³ÌID£¬Èç¹ûµ÷Óýø³ÌûÓÐ×Ó½ø³Ì£¬µ÷Óþͻáʧ°Ü£¬´Ëʱwait·µ»Ø-1£¬Í¬Ê±errno±»ÖÃΪECHILD¡£
ÏÂÃæ¾ÍÈÃÎÒÃÇÓÃÒ»¸öÀý×ÓÀ´ÊµÕ½Ó¦ÓÃÒ»ÏÂwaitµ÷ÓÃ:
/* wait1.c */
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main()
{
pid_t pc, pr;
pc = fork();
if ( pc < 0 ) /* Èç¹û³ö´í */
{
printf("create child prcocess error: %s\n", strerror(errno));
exit(1);
}
else if ( pc == 0) /* Èç¹ûÊÇ×Ó½ø³Ì */
{
printf("I am child process with pid %d \n", getpid());
sleep(3);/* ˯Ãß3ÃëÖÓ */
exit(0);
}
else /* Èç¹ûÊǸ¸½ø³Ì */
{
printf("Now in parent process, pid = %d\n", getpid());
printf("I am waiting child process to exit.\n");
pr = wait(NULL); /* ÔÚÕâÀïµÈ´ý×Ó½ø³Ì½áÊø */
if ( pr > 0 ) /*×Ó½ø³ÌÕý³£·µ»Ø*/
printf("I catched a child process with pid of %d\n", pr);
else /*³ö´í*/
printf("error: %s\n.\n", strerror(errno));
}
exit(0);
}
±àÒë²¢ÔËÐУº
$ gcc wait1.c -o wait1
$ ./wait1
I am child process with pid 2351
Now in parent process, pid = 2350
I am waiting child process to exit.
I catched a child process with pid of 2351
¿ÉÒÔÃ÷ÏÔ×¢Òâµ½£¬ÔÚµÚ2Ðнá¹û´òÓ¡³öÀ´Ç°ÓÐ10ÃëÖӵĵȴ
Ïà¹ØÎĵµ£º
2009 Äê 4 ÔÂ 23 ÈÕ
±¾ÎÄÖÐÎÒÃÇÕë¶Ô Linux É϶àÏ̱߳à³ÌµÄÖ÷ÒªÌØÐÔ×ܽá³ö 5 Ìõ¾Ñ飬ÓÃÒÔ¸ÄÉÆ Linux ¶àÏ̱߳à³ÌµÄÏ°¹ßºÍ±ÜÃâÆäÖеĿª·¢ÏÝÚå¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇ´©²åһЩ Windows µÄ±à³ÌÓÃÀýÓÃÒÔ¶Ô±È Linux ÌØÐÔ£¬ÒÔ¼ÓÉî¶ÁÕßÓ¡Ïó¡£
±³¾°
Linux ƽ̨ÉϵĶàÏ̳߳ÌÐò¿ª·¢Ïà¶ÔÓ¦ÆäËûƽ̨£¨±ÈÈç Windows£©µÄ¶àÏß³Ì API ÓÐһЩϸ΢ ......
½ø³ÌÊDzÙ×÷ϵͳÌṩµÄ×î¹ÅÀÏ£¬×îÖØÒªµÄ³éÏóÖ®Ò»£¬Ëü¶Ô¿ª·¢ÈËÔ±ºÍ²Ù×÷ÈËÔ±Òþ²ØÁËÁ½¸ö»ù±¾µÄÓ²¼þ×ÊÔ´£º´¦ÀíÆ÷ºÍ´æ´¢Æ÷¡£½ø³ÌµÄÖØÒªÐÔÔÚÓÚËüÓªÔì³ö¸öÊý²»ÊÜÎïÀí´¦ÀíÆ÷ÏÞÖƵÄÐéÄâ´¦ÀíÆ÷²¢ÎªÃ¿¸öÐéÄâ´¦ÀíÆ÷Å䱸Á˶ÀÁ¢µÄ£¬ÈÝÁ¿²»ÊÜÎïÀíÄÚ´æ´óСÏÞÖƵÄÄÚ´æ¿Õ¼ä¡£ÕâЩÐéÄâ´¦ÀíÆ÷ΪӦÓóÌÐòÄ£Äâ³öÒ»¸öºÍÎïÀí´¦ÀíÆ÷¼¸ºõÏàͬµÄ»·¾³£ºÃ¿ ......
1 ÒýÑÔ
¡¡¡¡Ị̈߳¨thread£©¼¼ÊõÔçÔÚ60Äê´ú¾Í±»Ìá³ö£¬µ«ÕæÕýÓ¦ÓöàÏ̵߳½²Ù×÷ϵͳÖÐÈ¥£¬ÊÇÔÚ80Äê´úÖÐÆÚ£¬solarisÊÇÕâ·½ÃæµÄٮٮÕß¡£´«Í³µÄUnixÒ²Ö§³ÖÏ̵߳ĸÅÄµ«ÊÇÔÚÒ»¸ö½ø³Ì£¨process£©ÖÐÖ»ÔÊÐíÓÐÒ»¸öỊ̈߳¬ÕâÑù¶àÏ߳̾ÍÒâζ×Ŷà½ø³Ì¡£ÏÖÔÚ£¬¶àÏ̼߳¼ÊõÒѾ±»Ðí¶à²Ù×÷ϵͳËùÖ§³Ö£¬°üÀ¨Windows/NT£¬µ±È»£¬Ò²°üÀ¨Linux¡£
......
http://www.askwan.com/post/28/
haproxy+keepalived
LinuxÆóÒµ¼¯Èº
http://book.51cto.com/art/200806/76015.htm#
µÚÒ»²½:rsyncͬ²½webÊý¾Ý£¨²âÊÔͨ¹ý²¢ÇÒ×Ô¼º¼ÓÈëÁËsshµÄRSA keyÑéÖ¤£©
http://www.linuxsir.org/main/?q=node/256 rsync ·þÎñÆ÷¼ÜÉè·½·¨ v0.1b £¨ÕýÔÚÐÞ¶©ÖУ©
µÚ¶þ²½:°²×°heartbeat²¢ÇÒ¿ ......
ѧ¶«Î÷£¬ÍùÍùʵÀý²ÅÊÇ×îÈÃÈ˸ÐÐËȤµÄ£¬ÀÏÊÇѧ»ù´¡ÀíÂÛ£¬²»¶¯ÊÖ£¬¸Ð¾õûÓгɾ͸У¬ºÇºÇ¡£
ÏÂÃæÏÈÀ´Ò»¸öʵÀý¡£ÎÒÃÇͨ¹ý´´½¨Á½¸öÏß³ÌÀ´ÊµÏÖ¶ÔÒ»¸öÊýµÄµÝ¼Ó¡£
»òÐíÕâ¸öʵÀýûÓÐʵ¼ÊÔËÓõļÛÖµ£¬µ«ÊÇÉÔ΢¸Ä¶¯Ò»Ï£¬ÎÒÃǾͿÉÒÔÓõ½ÆäËûµØ·½È¥À¡£
ÏÂÃæÊÇÎÒÃǵĴúÂ룺
/*thread_example.c : c multiple thread p ......