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

linux C forkº¯Êý

´´½¨Ð½ø³Ì£ºforkº¯Êý
1.1.1. forkº¯Êý¸Éʲô£¿
     #include <sys/types.h>
     #include <unistd.h>
     pid_t fork(void);
      ‘fork()’º¯ÊýÓÃÓÚ´ÓÒÑ´æÔÚ½ø³ÌÖд´½¨Ò»¸öнø³Ì¡£Ð½ø³Ì³ÆΪ×Ó½ø³Ì£¬¶øÔ­½ø³Ì³ÆΪ¸¸½ø³Ì¡£Äã¿ÉÒÔͨ¹ý¼ì²é‘fork()’º¯ÊýµÄ·µ»ØÖµÖªµÀÄĸöÊǸ¸½ø³Ì£¬ÄĸöÊÇ×Ó½ø³Ì¡£¸¸½ø³ÌµÃµ½µÄ·µ»ØÖµÊÇ×Ó½ø³ÌµÄ½ø³ÌºÅ£¬¶ø×Ó½ø³ÌÔò·µ»Ø0¡£ÒÔÏÂÕâ¸ö·¶Àý³ÌÐò˵Ã÷ËüµÄ»ù±¾¹¦ÄÜ£º
     pid_t pid;
     switch (pid = fork())
     {
     case -1:
         /* ÕâÀïpidΪ-1£¬forkº¯Êýʧ°Ü */
         /* һЩ¿ÉÄܵÄÔ­ÒòÊÇ */
         /* ½ø³ÌÊý»òÐéÄâÄÚ´æÓþ¡ */
         perror("The fork failed!");
         break;
     case 0:
         /* pidΪ0£¬×Ó½ø³Ì */
         /* ÕâÀÎÒÃÇÊǺ¢×Ó£¬Òª×öʲô£¿ */
         /* ... */
         /* µ«ÊÇ×öÍêºó, ÎÒÃÇÐèÒª×öÀàËÆÏÂÃ棺 */
         _exit(0);
     default:
         /* pid´óÓÚ0£¬Îª¸¸½ø³ÌµÃµ½µÄ×Ó½ø³ÌºÅ */
         printf("Child's pid is %d\n",pid);
     }
      µ±È»£¬ÓÐÈË¿ÉÒÔÓÑif() ... else ...’Óï¾äÈ¡´ú‘switch()’Óï¾ä£¬µ«ÊÇÉÏÃæµÄÐÎʽÊÇÒ»¸öÓÐÓõĹßÓ÷½·¨¡£
ÖªµÀ×Ó½ø³Ì×Ô¸¸½ø³Ì¼Ì³Ðʲô»òδ¼Ì³Ðʲô½«ÓÐÖúÓÚÎÒÃÇ¡£ÏÂÃæÕâ¸öÃûµ¥»áÒòΪ²»Í¬UnixµÄʵÏÖ¶ø·¢Éú±ä»¯£¬ËùÒÔ»òÐí׼ȷÐÔÓÐÁËË®·Ý¡£Çë×¢Òâ×Ó½ø³ÌµÃµ½µÄÊÇÕâЩ¶«Î÷µÄ *¿½±´*£¬²»ÊÇËüÃDZ¾Éí¡£
ÓÉ×Ó½ø³Ì×Ô¸¸½ø³Ì¼Ì³Ðµ½£º
½


Ïà¹ØÎĵµ£º

LinuxÄں˸ßΣ©¶´ Linuxϵͳϵͳ¿ÉÄÜÊܹ¥»÷,Ç××Ô²âÊÔ

Äں˰汾£º
Linux XOK 2.6.18-128.1.6.el5.centos.plus #1 SMP Thu Apr 2 12:53:36 EDT 2009 i686 i686 i386 GNU/Linux
ÂíÉϲâÊÔ£º
×¢Òâ²âÊÔÖпÉÄܵ¼ÖÂËÀ»ú¡£Çë²»ÒªÔÚÉú²ú»·¾³ÖвâÊÔ¡£
Èç¹ûÄãÏ£ÍûÇ×ÊÖÑéÖ¤´Ë©¶´£¬Äã¿ÉÒÔÏÂÔØÏÂÁÐÁ½¸ö´úÂë°ü²âÊÔ£¨ÓпÉÄܵ¼ÖÂϵͳ²»Îȶ¨£¬µ±»úµÈÏÖÏ󣬺ó¹û×Ô¸º£©£º
¾ÍÏÂÔØÕâ¸ö¼´¿É£ºhttp ......

LINUXÍøÂçÅäÖÃÎļþ


ÔÚ
linux
ϵͳÖУ¬
TCP/IP
ÍøÂçÊÇͨ¹ýÈô¸É¸öÎı¾Îļþ½øÐÐÅäÖõģ¬ÐèÒª±à¼­ÕâЩÎļþÀ´Íê³ÉÁªÍø¹¤×÷¡£ÏµÍ³ÖÐÖØÒªµÄÓйØÍøÂçÅäÖÃÎļþΪ£º
 
¡ô
/etc/sysconfig/network
¡ô
/etc/HOSTNAME
¡ô
/etc/hosts
¡ô
/etc/services
¡ô
/etc/host.conf
¡ô
/etc/nsswitch.conf
¡ô
/etc/resolv.conf
¡ô
/etc/r ......

Linuxϵͳµ÷Óûã×Ü

¶ÔÓÚ²»Í¬µÄLinuxÄں˰汾£¬´ËÁбí¿ÉÄܲ»Í¬£¬»ùÓÚºóÏò¼æÈÝÐÔ£¬Ëæ×ÅLinuxÄں˰汾ºÅµÄÔö¼Ó£¬´ËÁбí¿ÉÄÜ»á±ä³¤¡£´ËÁбíΪ2.6.24-16Äں˰汾ÓÚ/usr/include/asm/unistd_32.hÖÐÁгöµÄ324¸öϵͳµ÷Óúš£
#define __NR_restart_syscall 0
#define __NR_exit 1
#define __NR_fork 2
#define __NR_read 3
#define ......

ʹÓÃCÓïÑÔÀ©Õ¹Python£¨Ò»£©

¿ª·¢»·¾³£ºUbuntu9.10,python2.6,gcc4.4.11,ubuntuϵÄpythonÔËÐаüºÍ¿ª·¢°üÊÇ·Ö¿ªµÄ£¬Òò´ËÐèÒªÔÚÐÂÀûµÃÀïÃæ°²×°python-all-dev,´Ó¶ø¿ÉÒÔÔÚ´úÂëÖÐÒýÓÃpythonµÄÍ·ÎļþºÍ¿â¡£2.ÏÂÃæÊÇÒ»¸ö×î¼òµ¥µÄ¿ÉÒÔ¹©pythonµ÷ÓõÄcÀ©Õ¹Ä£¿é£¬¼ÙÉèc³ÌÐòÎļþÃûΪfoo.c:´úÂë#include <Python.h>
static PyObject* foo_b ......

C/C++λ²Ù×÷

C/C++λ²Ù×÷
Ò»¡¢´«Í³µÄC·½Ê½Î»²Ù×÷£º
1.»ù±¾²Ù×÷£º
  ʹÓÃÒ»¸öunsigned int±äÁ¿À´×÷ΪλÈÝÆ÷¡£
2.²Ù×÷·û£º
|  °´Î»»ò²Ù×÷·û£ºresult=exp1|exp2;µ±exp1ºÍexp2ÖжÔӦλÖÐÖÁÉÙÓÐÒ»¸öΪ1ʱ£¬resultÖжÔӦλΪ1£¬·ñÔòΪ0¡£
&  °´Î»Óë²Ù×÷·û£º£ºresult=exp1&exp2;µ±exp1ºÍexp2ÖжÔӦλȫΪ1ʱ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ