linuxÖÐfork£¨£©º¯ÊýÏê½â
Ò»¡¢forkÈëÃÅ֪ʶ
ÏÈ¿´Ò»¸öÀý×Ó£º
/*
* fork_test.c
* version 1
* Created on: 2010-5-29
* Author: wangth
*/
#include <unistd.h>;
#include <stdio.h>
int main ()
{
pid_t fpid; //fpid±íʾforkº¯Êý·µ»ØµÄÖµ
//´Ëʱ½öÓÐÒ»¸ö½ø³Ì
fpid=fork();
//´Ëʱ²Ù×÷ϵͳÖÐÒѾÓÐÁ½¸ö½ø³ÌÔÚͬʱÔËÐÐ
if (fpid < 0)
printf("error in fork!");
else if (fpid == 0)
printf("I am the child process, my process id is %d\n",getpid());
else
printf("I am the parent process, my process id is %d\n",getpid());
return 0;
}
ÔËÐнá¹ûÊÇ£º
I am the parent process, my process id is 2365
I am the child process, my process id is 2367
Ò»¸ö½ø³Ì£¬°üÀ¨´úÂë¡¢Êý¾ÝºÍ·ÖÅä¸ø½ø³ÌµÄ×ÊÔ´¡£fork£¨£©º¯Êýͨ¹ýϵͳµ÷Óô´½¨Ò»¸öÓëÔÀ´½ø³Ì¼¸ºõÍêÈ«ÏàͬµÄ½ø³Ì£¬Ò²¾ÍÊÇÁ½¸ö½ø³Ì¿ÉÒÔ×öÍêÈ«ÏàͬµÄÊ£¬µ«Èç¹û³õʼ²ÎÊý»òÕß´«ÈëµÄ±äÁ¿²»Í¬£¬Á½¸ö½ø³ÌÒ²¿ÉÒÔ×ö²»Í¬µÄÊ¡£
Ò»¸ö½ø³Ìµ÷ÓÃfork£¨£©º¯Êýºó£¬ÏµÍ³ÏȸøеĽø³Ì·ÖÅä×ÊÔ´£¬ÀýÈç´æ´¢Êý¾ÝºÍ´úÂëµÄ¿Õ¼ä¡£È»ºó°ÑÔÀ´µÄ½ø³ÌµÄËùÓÐÖµ¶¼¸´ÖƵ½ÐµÄнø³ÌÖУ¬Ö»ÓÐÉÙÊýÖµÓëÔÀ´µÄ½ø³ÌµÄÖµ²»Í¬¡£Ï൱ÓÚ¿Ë¡ÁËÒ»¸ö×Ô¼º¡£
ÔÚÓï¾äpid=fork()֮ǰ£¬Ö»ÓÐÒ»¸ö½ø³ÌÔÚÖ´ÐÐÕâ¶Î´úÂ룬µ«ÔÚÕâÌõÓï¾äÖ®ºó£¬¾Í±ä³ÉÁ½¸ö½ø³ÌÔÚÖ´ÐÐÁË£¬ÕâÁ½¸ö½ø³ÌµÄ¼¸ºõÍêÈ«Ïàͬ£¬½«ÒªÖ´ÐеÄÏÂÒ»ÌõÓï¾ä¶¼ÊÇif(pid<0)……
ΪʲôÁ½¸ö½ø³ÌµÄpid²»Í¬ÄØ£¬ÕâÓëforkº¯ÊýµÄÌØÐÔÓйء£forkµ÷ÓõÄÒ»¸öÆæÃîÖ®´¦¾ÍÊÇËü½ö½ö±»µ÷ÓÃÒ»´Î£¬È´Äܹ»·µ»ØÁ½´Î£¬Ëü¿ÉÄÜÓÐÈýÖÖ²»Í¬µÄ·µ»ØÖµ£º
1£©ÔÚ¸¸½ø³ÌÖУ¬fork·µ»Øд´½¨×Ó½ø³ÌµÄ½ø³ÌID£»
2£©ÔÚ×Ó½ø³ÌÖУ¬fork·µ»Ø0£»
3£©Èç¹û³öÏÖ´íÎó£¬fork·µ»ØÒ»¸ö¸ºÖµ£»
ÔÚforkº¯ÊýÖ´ÐÐÍê±Ïºó£¬Èç¹û´´½¨Ð½ø³Ì³É¹¦£¬Ôò³öÏÖÁ½¸ö½ø³Ì£¬Ò»¸öÊÇ×Ó½ø³Ì£¬Ò»¸öÊǸ¸½ø³Ì¡£ÔÚ×Ó½ø³ÌÖУ¬forkº¯Êý·µ»Ø0£¬ÔÚ¸¸½ø³ÌÖУ¬fork·µ»Øд´½¨×Ó½ø³ÌµÄ½ø³ÌID¡£ÎÒÃÇ¿ÉÒÔͨ¹ýfork·µ»ØµÄÖµÀ´Åжϵ±Ç°½ø³ÌÊÇ×Ó½ø³Ì»¹ÊǸ¸½ø³Ì¡£
fork³ö´í¿ÉÄÜÓÐÁ½ÖÖÔÒ
Ïà¹ØÎĵµ£º
¹úÍâ
¡¡¡¡http://lwn.net/
¡¡¡¡http://www.tldp.org/
¡¡¡¡https://rhn.redhat.com/
¡¡¡¡http://www.justlinux.com/
¡¡¡¡http://www.linuxtoday.com/
¡¡¡¡http://www.linuxquestions.org/
¡¡¡¡http://www.fokus.gmd.de/linux/
¡¡¡¡http://www.linux-tutorial.info/
¡¡¡¡http://www.freebsdforums.org/forums/
¡¡¡¡ ......
tar
-c: ½¨Á¢Ñ¹Ëõµµ°¸
-x£º½âѹ
-t£º²é¿´ÄÚÈÝ
-r£ºÏòѹËõ¹éµµÎļþĩβ׷¼ÓÎļþ
-u£º¸üÐÂÔѹËõ°üÖеÄÎļþ
ÕâÎå¸öÊǶÀÁ¢µÄÃüÁѹËõ½âѹ¶¼ÒªÓõ½ÆäÖÐÒ»¸ö£¬¿ÉÒԺͱðµÄÃüÁîÁ¬Óõ«Ö»ÄÜÓÃÆäÖÐÒ»¸ö¡£ÏÂÃæµÄ²ÎÊýÊǸù¾ÝÐèÒªÔÚѹËõ»ò½âѹµµ°¸Ê±¿ÉÑ¡µÄ¡£
-z£ºÓÐgzipÊôÐÔµÄ
-j£ºÓÐbz2ÊôÐÔµÄ
-Z£ºÓÐcompressÊôÐ﵀ ......
ÔÚ¿ª·¢¹ý³ÌÖУ¬±ØÈ»»á³öÏÖ¶àÈËͬʱ¹¤×÷¡¢Ð×ŵÄÇé¿ö£¬ÔÚǶÈëʽ¿ª·¢ÏîÄ¿ÖиüΪƽ³££¬ÕâÑù¿ÉÒÔ¼Ó¿ìÏîÄ¿ÖÜÆÚ£¬Îª²úÆ·ÉÏÊÐÕ¼µÃʱ¼äÏÈ»ú¡£Ä¿Ç°£¬Ê¹ÓÃlinux×÷Ϊ¿ª·¢²úÆ·µÄ²Ù×÷ϵͳÇé¿öÔ½À´Ô½¶à£¬Ê¹ÓÃÔ½À´Ô½¹ã·º¡£ÎªÁ˽»²æ±àÒ룬ΪÁË×î½Ó½ü¿ª·¢Ä¿±ê£¬ÎÒÃÇÒ»°ã¶¼»á×Ô¼º´î½¨Ò»Ì¨linux¿ª·¢·þÎñÆ÷¡£linux¿ª·¢·þÎñÆ÷ ......
Ê×ÏÈÏÂÔØÒ»¸ögrubfordos£¬´ÓÕâÀïϾÍÊÇÁË£¬http://download.csdn.net/source/1326121
ºÜСµÄ£¬²Å190k×óÓÒ£¬Ö±½Ó·ÅÖÃÔÚcÅÌ£¬È»ºó£¬´ò¿ªcÅÌ£¬ÔÚÎļþ¼ÐÑ¡ÏîÀïÃ棬°ÑϵͳÒþ²ØÑ¡Ïî´ò¿ª£¬ÏµÍ³±£»¤ÎļþÒ²´ò¿ª£¬¾Í¿ÉÒÔ¿´µ½Ò»¸öboot.iniÎļþ£¬ÔÚboot.iniÀïÃæÌí¼ÓÒ»C£º\grldr="grub for dos"
OK ¡£
Æô¶¯Ã»ÓÐÎÊÌâÁË¡£
°ÑlinuxµÄ°²× ......