CÓïÑÔ±àдlinuxϵÄÊØ»¤½ø³Ì
ÀûÓÃ
ÏÂÔصÄÕâ¶Î´úÂ룬³É¹¦ÊµÏÖÁËÊØ»¤½ø³Ì£¬ÔÀ´ÊØ»¤½ø³ÌÊǺܼòµ¥µÄÊÂÇé¡£
¡¡¡¡ÔÚmainº¯ÊýÖÐÖ´ÐÐ
¡¡¡¡init_daemon();//³õʼ»¯ÎªDaemon
¡¡¡¡¾Í¿ÉÒ԰ѽø³Ì±ä³ÉÊØ»¤½ø³Ì
¡¡¡¡
#include
#include
#include
#include
#include
void
init_daemon(void
)
{
int
pid;
int
i;
if
(pid=fork())
exit
(0);//ÊǸ¸½ø³Ì£¬½áÊø¸¸½ø³Ì
else
if
(pid< 0)
exit
(1);//forkʧ°Ü£¬Í˳ö
//ÊǵÚÒ»×Ó½ø³Ì£¬ºǫ́¼ÌÐøÖ´ÐÐ
setsid();//µÚÒ»×Ó½ø³Ì³ÉΪеĻỰ×鳤ºÍ½ø³Ì×鳤
//²¢Óë¿ØÖÆÖն˷ÖÀë
if
(pid=fork())
exit
(0);//ÊǵÚÒ»×Ó½ø³Ì£¬½áÊøµÚÒ»×Ó½ø³Ì
else
if
(pid< 0)
exit
(1);//forkʧ°Ü£¬Í˳ö
//Êǵڶþ×Ó½ø³Ì£¬¼ÌÐø
//µÚ¶þ×Ó½ø³Ì²»ÔÙÊǻỰ×鳤
for
(i=0;i< NOFILE;++i)//¹Ø±Õ´ò¿ªµÄÎļþÃèÊö·û
close
(i);
chdir("/tmp"
);//¸Ä±ä
¹¤×÷Ŀ¼µ½/tmp
umask(0);//ÖØÉèÎļþ´´½¨ÑÚÄ£
return
;
}
Ïà¹ØÎĵµ£º
2.1 ¿É²âÐÔÎÊÌâÏê½â(2)
½ÓÏÂÀ´ÎÒÃÇÌÖÂÛÖصãÎÊÌ⣺¸²¸ÇÊäÈë¡£Ò»¸öº¯Êý£¬ÊäÈë»áÓÐÄÄЩÄØ£¿ÊäÈë°üÀ¨Á½·½Ã棺ÍⲿÊäÈ룬ÄÚ²¿ÊäÈë¡£ÍⲿÊäÈëÈÝÒ×Àí½â£¬¾ÍÊǺ¯ÊýÍⲿ¿ÉÒÔÉ趨µÄÊäÈ룬°üÀ¨²ÎÊý£¬È«¾Ö±äÁ¿£¬³ÉÔ±±äÁ¿¡£
&nb ......
ʲôʱºòÐèÒª´´½¨Ï̳߳ØÄØ£¿¼òµ¥µÄ˵£¬Èç¹ûÒ»¸öÓ¦ÓÃÐèҪƵ·±µÄ´´½¨ºÍÏú»ÙỊ̈߳¬¶øÈÎÎñÖ´ÐеÄʱ¼äÓַdz£¶Ì£¬ÕâÑùÏ̴߳´½¨ºÍÏú»ÙµÄ´øÀ´µÄ¿ªÏú¾Í²»ÈݺöÊÓ£¬ÕâʱҲÊÇÏ̳߳ظóö³¡µÄ»ú»áÁË¡£Èç¹ûÏ̴߳´½¨ºÍÏú»Ùʱ¼äÏà±ÈÈÎÎñÖ´ÐÐʱ¼ä¿ÉÒÔºöÂÔ²»¼Æ£¬ÔòûÓбØҪʹÓÃÏ̳߳ØÁË¡£
ÏÂÃæÊÇLinuxϵͳÏÂÓÃCÓïÑÔ´´½¨µÄÒ»¸öÏ̳߳ء£Ï̳߳ػ ......
C/C++ optimizing compilers are great--but there *are* a few techniques for hand-tuning your code to run as efficiently as possible on the AMD Athlon64 and Opteron processors, especially when developing DLLs, device drivers, or other performance-bound pieces of code.
Alan Zeichick
Share | ......
1.ÒýÑÔ
C++ÓïÑԵĴ´½¨³õÖÔÊÇ“a better
C”£¬µ«ÊÇÕâ²¢²»Òâζ×ÅC++ÖÐÀàËÆCÓïÑÔµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýËù²ÉÓõıàÒëºÍÁ¬½Ó·½Ê½ÓëCÓïÑÔÍêÈ«Ïàͬ¡£×÷ΪһÖÖÓûÓëC¼æÈݵÄÓïÑÔ£¬C++±£ÁôÁËÒ»²¿·Ö¹ý³Ì
ʽÓïÑÔµÄÌص㣨±»ÊÀÈ˳ÆΪ“²»³¹µ×µØÃæÏò¶ÔÏ󔣩£¬Òò¶øËü¿ÉÒÔ¶¨Òå²»ÊôÓÚÈκÎÀàµÄÈ«¾Ö±äÁ¿ºÍº¯Êý¡£µ«ÊÇ£¬C++ ......
´óѧÒѾÀ´µ½ÁË×îÖØÒªµÄʱÆÚÁË£¬ÎÒ²»ÄÜÔÙÒ»ÊÂÎÞ³ÉÁË¡£¹â˵ûÓã¬ËùÒÔ¾ÍÔÚÕâÀïдÏÂÎÄÕ£¬ÒԼǼÎҵijɳ¤Àú³Ì¡£
ÕâѧÆÚ¸ÕºÃѧµ½Êý¾Ý½á¹¹£¬ÄǾͽ«ÌâÄ¿·ÖÎöµÄ¹ý³Ì¼°´úÂëдÏÂÀ´£¬¹©ÒÔºó×Ô¼ºÈ¡Éá¡£Òò±¾ÈËˮƽһ°ã£¬ËùÒÔ´úÂë²¢²»Ò»¶¨ÊÇ×îÓŵģ¬µ«ÊÇÎÒ»áŬÁ¦¸Ä½ø£¬×ö×îºÃµÄ×Ô¼º£¡ ......