LinuxϵĹܵÀ±à³Ì¼¼Êõ dupº¯ÊýºÍdup2º¯Êý
dupºÍdup2Ò²ÊÇÁ½¸ö·Ç³£ÓÐÓõĵ÷Óã¬ËüÃǵÄ×÷Óö¼ÊÇÓÃÀ´¸´ÖÆÒ»¸öÎļþµÄÃèÊö·û¡£ËüÃǾ³£ÓÃÀ´Öض¨Ïò½ø³ÌµÄstdin¡¢stdoutºÍstderr¡£ÕâÁ½¸öº¯ÊýµÄ ÔÐÎÈçÏ£º
#include <unistd.h>
int dup( int oldfd );
int dup2( int oldfd, int targetfd )
ÀûÓú¯Êýdup£¬ÎÒÃÇ¿ÉÒÔ¸´ÖÆÒ»¸öÃèÊö·û¡£´«¸ø¸Ãº¯ÊýÒ»¸ö¼ÈÓеÄÃèÊö·û£¬Ëü¾Í»á·µ»ØÒ»¸öеÄÃèÊö·û£¬Õâ¸öеÄÃèÊö·ûÊÇ´«¸øËüµÄÃèÊö·ûµÄ¿½±´¡£ÕâÒâζ×Å£¬ÕâÁ½¸öÃèÊö·û¹²Ïíͬһ¸öÊý¾Ý½á¹¹
¡£ÀýÈ磬Èç¹ûÎÒÃǶÔÒ»¸öÎļþÃèÊö·ûÖ´ÐÐlseek²Ù×÷£¬µÃµ½µÄµÚÒ»¸öÎļþµÄλÖú͵ڶþ¸öÊÇÒ»ÑùµÄ¡£ÏÂÃæÊÇÓÃÀ´ËµÃ÷dupº¯ÊýʹÓ÷½·¨µÄ´úÂëƬ¶Î£º
int fd1, fd2;
...
fd2 = dup( fd1 );
ÐèҪעÒâµÄÊÇ£¬ÎÒÃÇ¿ÉÒÔÔÚµ÷ÓÃfork֮ǰ½¨Á¢Ò»¸öÃèÊö·û£¬ÕâÓëµ÷ÓÃdup½¨Á¢ÃèÊö·ûµÄЧ¹ûÊÇÒ»ÑùµÄ£¬×Ó½ø³ÌҲͬÑù»áÊÕµ½Ò»¸ö¸´ÖƳöÀ´µÄÃèÊö·û¡£
dup2º¯Êý¸údupº¯ÊýÏàËÆ£¬µ«dup2º¯ÊýÔÊÐíµ÷ÓÃÕ߹涨һ¸öÓÐЧÃèÊö·ûºÍÄ¿±êÃèÊö·ûµÄid¡£dup2º¯Êý³É¹¦·µ»Øʱ£¬Ä¿±êÃèÊö·û£¨dup2º¯ÊýµÄµÚ
¶þ¸ö²ÎÊý£©½«±ä³ÉÔ´ÃèÊö·û£¨dup2º¯ÊýµÄµÚÒ»¸ö²ÎÊý£©µÄ¸´ÖÆÆ·£¬»»¾ä»°Ëµ£¬Á½¸öÎļþÃèÊö·ûÏÖÔÚ¶¼Ö¸Ïòͬһ¸öÎļþ£¬²¢ÇÒÊǺ¯ÊýµÚÒ»¸ö²ÎÊýÖ¸ÏòµÄÎļþ¡£ÏÂÃæ
ÎÒÃÇÓÃÒ»¶Î´úÂë¼ÓÒÔ˵Ã÷£º
int oldfd;
oldfd = open("app_log", (O_RDWR | O_CREATE), 0644 );
dup2( oldfd, 1 );
close( oldfd );
±¾ÀýÖУ¬ÎÒÃÇ´ò¿ªÁËÒ»¸öÐÂÎļþ£¬³ÆΪ“app_log”£¬²¢ÊÕµ½Ò»¸öÎļþÃèÊö·û£¬¸ÃÃèÊö·û½Ð×öfd1¡£ÎÒÃǵ÷ÓÃdup2º¯Êý£¬²ÎÊýΪoldfdºÍ1£¬Õâ»á
µ¼ÖÂÓÃÎÒÃÇдò¿ªµÄÎļþÃèÊö·ûÌæ»»µôÓÉ1´ú±íµÄÎļþÃèÊö·û£¨¼´stdout£¬ÒòΪ±ê×¼Êä³öÎļþµÄidΪ1£©¡£ÈκÎдµ½stdoutµÄ¶«Î÷£¬ÏÖÔÚ¶¼½«¸ÄΪд
ÈëÃûΪ“app_log”µÄÎļþÖС£ÐèҪעÒâµÄÊÇ£¬dup2º¯ÊýÔÚ¸´ÖÆÁËoldfdÖ®ºó£¬»áÁ¢¼´½«Æä¹Ø±Õ£¬µ«²»»á¹Øµôнü´ò¿ªµÄÎļþÃèÊö·û£¬ÒòΪÎļþÃèÊö
·û1ÏÖÔÚÒ²Ö¸ÏòËü¡£
ÏÂÃæÎÒÃǽéÉÜÒ»¸ö¸ü¼ÓÉîÈëµÄʾÀý´úÂë¡£»ØÒäһϱ¾ÎÄÇ°Ãæ½²µÄÃüÁîÐйܵÀ£¬ÔÚÄÇÀÎÒÃǽ«ls –1ÃüÁîµÄ±ê×¼Êä³ö×÷Ϊ±ê×¼ÊäÈëÁ¬½Óµ½wc –lÃüÁî¡£½ÓÏÂÀ´£¬ÎÒÃǾÍÓÃÒ»¸öC³ÌÐòÀ´¼ÓÒÔ˵Ã÷Õâ¸ö¹ý³ÌµÄʵÏÖ¡£´úÂëÈçÏÂÃæµÄʾÀý´úÂë3Ëùʾ¡£
ÔÚʾÀý´úÂë3ÖУ¬Ê×ÏÈÔÚµÚ9ÐдúÂëÖн¨Á¢Ò»¸ö¹ÜµÀ£¬È»ºó½«Ó¦ÓóÌÐò·Ö³ÉÁ½¸ö½ø³Ì£ºÒ»¸ö×Ó½
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
/*
* linux/kernel/floppy.c
*
* (C) 1991 Linus Torvalds
*/
/*
* 02.12.91 - Changed to static variables to indicate need for reset
* and recalibrate. This makes some things easier (output_byte reset
* checking etc), and means less i ......
½ñÌìµÄÒ»¸öºÜÖØÒªµÄÊÕ»ñ
Ò»¸öÖÂÃüµÄÃüÁî sudo chmod £R a+rwx * ÊÇÔÚµ±Ç°Îļþ¼ÐÏÂÃæµÄËùÓÐÎļþºÍÎļþ¼Ð¶¼ÊǿɶÁ ¿Éд ¿ÉÖ´ÐÐ
ÒÔÇ°°²×°phpcmsÔÚubuntuϵÄʱºò ¶¼ÊÇʧ°Ü¶ø¸æÖÕµÄ ½ñÌìÖÕÓڳɹ¦ ÁË
¾ÍÊÇÕâ¸öÃüÁî¾ÈÁËÎÒ ......
¹ÜµÀ£ºµ±´ÓÒ»¸ö½ø³ÌÁ¬½ÓÊý¾ÝÁ÷µ½ÁíÒ»¸ö½ø³Ìʱ£¬Ê¹ÓÃÊõÓï¹ÜµÀ£¨pipe£©¡£
££i nclude <unistd.h>
int pipe(int filedes[2]); //´´½¨¹ÜµÀ
pipe()˵Ã÷:
·µ»ØÖµ£º0³É¹¦£¬-1³ö´í¡£
Èç¹ûµ÷Óóɹ¦£¬Ôò½ø³Ì´ËʱÓÉÁËÁ½¸ö¶îÍâµÄ´ò¿ªÎļþÃèÊö·û£¬filedes[0]ÖеÄÖµÊǹܵÀµÄ¶ÁÈ¡¶Ë£¬¶øfiledes[1]ÊǹܵÀµÄдÈë¶Ë¡£
#include&l ......