LinuxÖض¨ÏòÏê½â
תÔØ£ºhttp://www.cnblogs.com/hexapodsoft/archive/2007/04/24/724902.html
I/OÖض¨ÏòÏê½â¼°Ó¦ÓÃʵÀý
1¡¢ »ù±¾¸ÅÄÕâÊÇÀí½âºóÃæµÄ֪ʶµÄÇ°ÌᣬÇëÎñ±ØÀí½â£©
a¡¢ I/OÖض¨Ïòͨ³£Óë FDÓйأ¬shellµÄFDͨ³£Îª10¸ö£¬¼´ 0¡«9£»
b¡¢ ³£ÓÃFDÓÐ3¸ö£¬Îª0£¨stdin£¬±ê×¼ÊäÈ룩¡¢1£¨stdout£¬±ê×¼Êä³ö£©¡¢2£¨stderr£¬±ê×¼´íÎóÊä³ö£©£¬Ä¬ÈÏÓëkeyboard¡¢monitor¡¢monitorÓйأ»
c¡¢ Óà < À´¸Ä±ä¶Á½øµÄÊý¾ÝÐŵÀ(stdin)£¬Ê¹Ö®´ÓÖ¸¶¨µÄµµ°¸¶Á½ø£»
d¡¢ Óà > À´¸Ä±äËͳöµÄÊý¾ÝÐŵÀ(stdout, stderr)£¬Ê¹Ö®Êä³öµ½Ö¸¶¨µÄµµ°¸£»
e¡¢ 0 ÊÇ < µÄĬÈÏÖµ£¬Òò´Ë < Óë 0<ÊÇÒ»ÑùµÄ£»Í¬Àí£¬> Óë 1> ÊÇÒ»ÑùµÄ£»
f¡¢ ÔÚIOÖض¨Ïò ÖУ¬stdout Óë stderr µÄ¹ÜµÀ»áÏÈ×¼±¸ºÃ£¬²Å»á´Ó stdin ¶Á½ø×ÊÁÏ£»
g¡¢ ¹ÜµÀ“|”(pipe line):ÉÏÒ»¸öÃüÁîµÄ stdout ½Óµ½ÏÂÒ»¸öÃüÁîµÄ stdin;
h¡¢ tee ÃüÁîÊÇÔÚ²»Ó°ÏìÔ±¾ I/O µÄÇé¿öÏ£¬½« stdout ¸´ÖÆÒ»·Ýµ½µµ°¸È¥;
i¡¢ bash£¨ksh£©Ö´ÐÐÃüÁîµÄ¹ý³Ì£º·ÖÎöÃüÁäÁ¿ÇóÖµ£ÃüÁîÌæ´ú£¨``ºÍ$( )£©£Öض¨Ïò£Í¨Åä·ûÕ¹¿ª£È·¶¨Â·¾¶£Ö´ÐÐÃüÁ
j¡¢
( ) ½« command group ÖÃÓÚ sub-shell È¥Ö´ÐУ¬Ò²³Æ nested
sub-shell£¬ËüÓÐÒ»µã·Ç³£ÖØÒªµÄÌØÐÔÊÇ£º¼Ì³Ð¸¸shellµÄStandard input, output, and error plus
any other open file descriptors¡£
k¡¢ exec ÃüÁ³£ÓÃÀ´Ìæ´úµ±Ç° shell ²¢ÖØÐÂÆô¶¯Ò»¸ö shell£¬»»¾ä»°Ëµ£¬²¢Ã»ÓÐÆô¶¯×Ó shell¡£Ê¹ÓÃÕâÒ»ÃüÁîʱÈκÎÏÖÓл·¾³¶¼½«»á±»Çå³ý¡£exec ÔÚ¶ÔÎļþÃèÊö·û½øÐвÙ×÷µÄʱºò£¬Ò²Ö»ÓÐÔÚÕâʱ£¬exec ²»»á¸²¸ÇÄ㵱ǰµÄ shell »·¾³¡£
2¡¢ »ù±¾IO
cmd > file °Ñ stdout Öض¨Ïòµ½ file ÎļþÖУ»
cmd >> file °Ñ stdout Öض¨Ïòµ½ file ÎļþÖÐ(×·¼Ó)£»
cmd 1> fiel °Ñ stdout Öض¨Ïòµ½ file ÎļþÖУ»
cmd > file 2>&1 °Ñ stdout ºÍ stderr Ò»ÆðÖض¨Ïòµ½ file ÎļþÖУ»
cmd 2> file °Ñ stderr Öض¨Ïòµ½ file ÎļþÖУ»
cmd 2>> file °Ñ stderr Öض¨Ïòµ½ file ÎļþÖÐ(×·¼Ó)£»
cmd >> file 2>&1 °Ñ stderr ºÍ stderr Ò»ÆðÖض¨Ïòµ½ file ÎļþÖÐ(×·¼Ó)£»
cmd < file >file2 cmd ÃüÁîÒÔ file Îļþ×÷Ϊ stdin£¬ÒÔ file2 Îļþ×÷Ϊ stdout£»
cat <>file ÒÔ¶ÁдµÄ·½Ê½´ò¿ª file£»
cmd < file cmd ÃüÁîÒÔ file Îļþ×÷Ϊ stdin£»
cmd << delimiter Here document£¬´Ó stdin ÖжÁÈ룬ֱÖÁ
Ïà¹ØÎĵµ£º
תÔØ×Ô£ºhttp://www.91linux.com/html/article/go/20090205/15634.html
bin = BINaries £¨binary)
/dev = devices
/etc = ETCetera
etcetera¸½¼ÓµÄÈË, ¸½¼ÓÎï, ÒÔ¼°ÆäËü, µÈµÈ
/lib = LIBrary
/proc = PROCesses
/sbin
= Superuser BINaries
/tmp = TeMPorary
/usr = Unix Shared
Resources
/var = ......
±¾ÎIJ¢·Ç½âÊÍʲôÊÇ·Ç×èÈûsocket£¬Ò²²»ÊǽéÉÜsocket APIµÄÓ÷¨£¬ È¡¶ø´úÌæµÄÊÇÈÃÄã¸ÐÊÜʵ¼Ê¹¤×÷ÖеĴúÂë±àд¡£ËäÈ»ºÜ¼òª£¬µ«Äã¿ÉÒÔͨ¹ýmanÊÖ²áÓëÆäËü×ÊÔ´·Ç¸»ÄãµÄ´úÂë¡£Çë×¢Òâ±¾½Ì³ÌËù˵µÄÖ÷Ì⣬Èç¹ûϸ˵£¬ÄÚÈÝ¿ÉÒÔ´ïµ½Ò»±¾ÊéÄÚÈÝ£¬Äã»á·¢ÏÖ±¾½Ì³ÌºÜÓÐÓá£
±¾½Ì³ÌÄÚÈÝÈçÏ£º
......
°æȨÉùÃ÷£ºÔ´´×÷Æ·£¬ÔÊÐíתÔØ£¬×ªÔØʱÇëÎñ±ØÒÔ³¬Á´½ÓÐÎʽ±êÃ÷ÎÄÕ Ôʼ³ö´¦ ¡¢×÷ÕßÐÅÏ¢ºÍ±¾ÉùÃ÷¡£·ñÔò½«×·¾¿·¨ÂÉÔðÈΡ£http://blog.csdn.net/Neverland2012
ÎÒÃǾ³£»áÈ¥ÏÂÔرð ......
Linux ÏûÏ¢Öض¨Ïò°ì·¨
command > filename
°Ñ±ê×¼Êä³öÖض¨Ïòµ½Ò»¸öÖ¸¶¨ÎļþÖÐ
command 1 > fielname
°Ñ±ê×¼Êä³öÖض¨Ïòµ½Ò»¸öÖ¸¶¨ÎļþÖÐ(ͬÉÏ)
command 2 > filename
°Ñ±ê×¼´íÎóÖض¨Ïòµ½Ò»¸öÎļþÖÐ
command >! filename
°Ñ±ê×¼Êä³öÖض¨Ïòµ½Ò»¸ö
Ö¸¶¨
ÎļþÖУ¬ÈôÎļþ´æÔÚ£¬Ôò¸²¸Ç
command >&am ......
/*
* ¸ÃÎļþÖеÄÁ½¸öº¯Êýread_pipeºÍwrite_pipeÊÇÉϲ㺯Êý
* readºÍwriteµÄµ×²ãʵÏÖ
*/
/*
* linux/fs/pipe.c
*
* (C) 1991 Linus Torvalds
*/
#include <signal.h>
#include <linux/sched.h>
// ÄÚ´æ¹ÜÀíÍ·Îļþ¡£º¬ÓÐÒ³Ãæ´óС¶¨Òåº ......