Linux fork()º¯Êýѧϰ
ÔÚ UNIX ϵͳÖУ¬Óû§´´½¨Ò»¸öнø³ÌµÄΨһ·½·¨¾ÍÊǵ÷ÓÃϵͳµ÷Óà fork¡£µ÷ Óà fork µÄ½ø³Ì³ÆΪ¸¸½ø³Ì£¬¶øд´½¨µÄ½ø³Ì½Ð×ö×Ó½ø³Ì¡£ÏµÍ³µ÷ÓõÄÓï·¨¸ñʽ£º
pid = fork();
ÔÚ´Óϵͳµ÷Óà fork Öзµ»Øʱ£¬Á½¸ö½ø³Ì³ýÁË·µ»ØÖµ pid ²»Í¬Í⣬¾ßÓÐÍêÈ«Ò»ÑùµÄÓû§¼¶ÉÏÏÂÎÄ¡£ÔÚ×Ó½ø³ÌÖУ¬pid µÄֵΪÁã¡£ÔÚϵͳÆô¶¯Ê±ÓɺËÐÄÄÚ ²¿µØ´´½¨µÄ½ø³Ì0ÊÇΨһ²»Í¨¹ýϵͳµ÷Óà fork ¶ø´´½¨µÄ½ø³Ì¡£
ºËÐÄΪϵͳµ÷Óà fork Íê³ÉÏÂÁвÙ×÷£º
Ϊнø³ÌÔÚ½ø³Ì±íÖзÖÅäÒ»¸ö¿ÕÏî¡£
Ϊ×Ó½ø³Ì¸³Ò»¸öΨһµÄ½ø³Ì±êʶºÅ (PID)¡£
×öÒ»¸ö¸¸½ø³ÌÉÏÏÂÎĵÄÂß¼¸±±¾¡£ÓÉÓÚ½ø³ÌµÄijЩ²¿·Ö£¬ÈçÕýÎÄÇø£¬¿ÉÄܱ»¼¸¸ö ½ø³ÌËù¹²Ïí£¬ËùÒÔºËÐÄÓÐʱֻҪÔö¼Óij¸öÇøµÄÒýÓÃÊý¼´¿É£¬¶ø²»ÊÇÕæµÄ½«¸ÃÇø¿½±´µ½Ò»¸ö еÄÄÚ´æÎïÀíÇø¡£
Ôö¼ÓÓë¸Ã½ø³ÌÏà¹ØÁªµÄÎļþ±íºÍË÷Òý½Úµã±íµÄÒýÓÃÊý¡£
¶Ô¸¸½ø³Ì·µ»Ø×Ó½ø³ÌµÄ½ø³ÌºÅ£¬¶Ô×Ó½ø³Ì·µ»ØÁã¡£
Àí½âϵͳµ÷Óà fork µÄʵÏÖÊÇÊ®·ÖÖØÒªµÄ£¬ÒòΪ×Ó½ø³Ì¾ÍÏó´ÓÌì¶ø½µÒ»ÑùµØ¿ªÊ¼ ËüµÄÖ´ÐÐÐòÁС£
ÏÂÃæÊÇϵͳµ÷Óà fork µÄËã·¨¡£ºËÐÄÊ×ÏÈÈ·ÐÅÓÐ×ã¹»µÄ×ÊÔ´À´³É¹¦Íê³É fork¡£ Èç¹û×ÊÔ´²»Âú×ãÒªÇó£¬Ôòϵͳµ÷Óà fork ʧ°Ü¡£Èç¹û×ÊÔ´Âú×ãÒªÇ󣬺ËÐÄÔÚ½ø³Ì ±íÖÐÕÒÒ»¸ö¿ÕÏ²¢¿ªÊ¼¹¹Ôì×Ó½ø³ÌµÄÉÏÏÂÎÄ¡£
Ëã·¨£ºfork
ÊäÈ룺ÎÞ
Êä³ö£º¶Ô¸¸½ø³ÌÊÇ×Ó½ø³ÌµÄ PID
¶Ô×Ó½ø³ÌÊÇ0
{
¼ì²é¿ÉÓõĺËÐÄ×ÊÔ´
È¡Ò»¸ö¿ÕÏеĽø³Ì±íÏîºÍΨһµÄ PID ºÅ
¼ì²éÓû§Ã»Óйý¶àµÄÔËÐнø³Ì
½«×Ó½ø³ÌµÄ״̬ÉèÖÃΪ“´´½¨”״̬
½«¸¸½ø³ÌµÄ½ø³Ì±íÖеÄÊý¾Ý¿½±´µ½×Ó½ø³Ì±íÖÐ
µ±Ç°Ä¿Â¼µÄË÷Òý½ÚµãºÍ¸Ä±äµÄ¸ùĿ¼(Èç¹û¿ÉÒÔ)µÄÒýÓÃÊý¼Ó1
Îļþ±íÖеĴò¿ªÎļþµÄÒýÓÃÊý¼Ó1
ÔÚÄÚ´æÖÐ×÷¸¸½ø³ÌÉÏÏÂÎĵĿ½±´
ÔÚ×Ó½ø³ÌµÄϵͳ¼¶ÉÏÏÂÎÄÖÐѹÈëÐéÉèϵͳ¼¶ÉÏÏÂÎIJã
/* ÐéÉèÉÏÏÂÎIJãÖк¬ÓÐʹ×Ó½ø³ÌÄÜ
* ʶ±ð×Ô¼ºµÄÊý¾Ý£¬²¢Ê¹×Ó½ø³Ì±»µ÷¶Èʱ
* ´ÓÕâÀ↑ʼÔËÐÐ
*/
if (ÕýÔÚÖ´ÐеĽø³ÌÊǸ¸½ø³Ì) {
½«×Ó½ø³ÌµÄ״̬ÉèÖÃΪ“¾ÍÐ÷”״̬
return (×Ó½ø³ÌµÄ PID) // ´Óϵͳµ½Óû§
}
else {
³õʼ»¯¼ÆʱÇø
return 0;
}
}
ÎÒÃÇÀ´¿´¿´ÏÂÃæµÄÀý×Ó¡£¸Ã³ÌÐò˵Ã÷µÄÊǾ¹ýϵͳµ÷Óà fork Ö®ºó£¬¶ÔÎļþµÄ¹²Ïí´æÈ¡¡£Óû§µ÷ÓøóÌÐòʱӦÓÐÁ½¸ö²ÎÊý£¬Ò»¸öÊÇÒѾÓеÄÎļþÃû£¬ÁíÍâÒ»¸öÊÇÒª´´½¨µÄÐÂÎļþÃû¡£¸Ã½ø³Ì´ò¿ªÒÑÓеÄÎļþ£¬´´½¨Ò»¸öÐÂÎļþ£¬È»ºó£¬¼Ù
Ïà¹ØÎĵµ£º
£¨L2CAPÐÒé¼ò½é£¬L2CAPÔÚBlueZÖеÄʵÏÖÒÔ¼°L2CAP±à³Ì½Ó¿Ú£©
Ò»£ºL2CAPÐÒé¼ò½é£º
Logical Link Control and Adaptation Protocol(L2CAP)
Âß¼Á¬½Ó¿ØÖƺÍÊÊÅäÐÒé (L2CAP) ΪÉϲãÐÒéÌṩÃæÏòÁ¬½ÓºÍÎÞÁ¬½ÓµÄÊý¾Ý·þÎñ£¬²¢Ìṩ¶àÐÒ鹦ÄܺͷָîÖØ×é²Ù×÷¡£L2CAP ³äÐíÉϲãÐÒéºÍÓ¦ÓÃÈí¼þ´«ÊäºÍ½ÓÊÕ×î´ó³¤¶ÈΪ 64K µÄ L2CAP Ê ......
ÎÊÌ⣺ÔÚLinuxÏÂÕý³£»»ÐеÄÎÄ×Ö£¬µ½ÁËWindowsϺ󣬲»ÔÙ»»ÐС£
ÔÚWindowsÏ»»ÐÐʱ£¬ÓÐÁ½¸ö×Ö·û£º»Ø³µ(\r)ºÍ»»ÐÐ(\n)¡£µ«ÔÚLinuxÏ£¬Ö»ÓÐÒ»¸ö»»ÐÐ(\n)
¿ÉʹÓÃunix2dosºÍdos2unixÃüÁî½øÐиñʽµÄת»»£º
²ÎÊý£º
-k ±£³ÖÊä³öÎļþºÍÊäÈëÎļþµÄÈÕÆÚʱ¼ä´Á²»±ä
-o file ĬÈÏģʽ . ½«fileת»»£ ......
1. Q. How do you find out the processes that are currently running or a particular user?
A. ps -au Myname (-u by effective user ID (supports names)) (a - all users)
2. Q. How do you kill a process?
A. kill -9 8 (process_id 8) or kill -9 %7 ( ......
1¡¢ÒýÑÔ
ÔÚlinuxϵͳÏ£¬Èç¹ûÄãÏÂÔز¢°²×°ÁËÓ¦ÓóÌÐò£¬ºÜÓпÉÄÜÔÚ¼üÈëËüµÄÃû³Æʱ³öÏÖ“command not
found”µÄÌáʾÄÚÈÝ¡£Èç¹ûÿ´Î¶¼µ½°²×°Ä¿±êÎļþ¼ÐÄÚ£¬ÕÒµ½¿ÉÖ´ÐÐÎļþÀ´½øÐвÙ×÷¾ÍÌ«·±ËöÁË¡£ÕâÉæ¼°µ½»·¾³±äÁ¿PATHµÄÉèÖÃÎÊÌ⣬¶øPATHµÄÉèÖÃÒ²
ÊÇÔÚlinux϶¨ÖÆ»·¾³±äÁ¿µÄÒ»¸ö×é³É²¿·Ö¡£±¾Î ......
ÉÏ週Òò為ÓÐһ̨ºÜ舊µÄ Linux ËÅ·þÆ÷ÐèÖØа²裝£¨簡稱 A
Ö÷機£©£¬Òò為ËùÓÐ資Á϶¼ÒÑ經備·Ý£¬ÇÒÒ²ÒÑ經確認無Èκηþ務ÔÚ這̨Ö÷機ÁË£¬ËùÒÔÒ²ºÜ·ÅÐĵÄÖعàÁË¡£²»過£¬ÖعàÁËÖ®áá²Å發現Ô來 ......