ãã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦ãã£ããç解ãã
ãã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦åå¼·ãããã¨ã«ã¤ãã¦æ¸ãã¦ã¿ããã¨æãã¾ãã
ä»åã¯ãæ¦è¦³ã«ã¤ãã¦ããµãã£ã¨ç解ã§ãããããªè³æã«ãªãããã«æ¸ãã¦ããããã¨æãã¾ãã èªãã§ããã ãã¨ãreadãwrite ã·ã¹ãã ã³ã¼ã«ã®è£å´ã§ä½ãèµ·ãã¦ãããè¥å¹²æ³åãã¤ãããã«ãªãããããã¾ããã
ããããåå¼·ããã¦ã¿ããã¨æãããæ¹ã®åèã«ãªãã°å¹¸ãã§ãã
ãã¡ã¤ã«ã·ã¹ãã ã®æ¦è¦³
ãã¡ã¤ã«ã·ã¹ãã ã«ã¤ãã¦è¦ã¦ããæã«ã¯ãï¼ã¤ã®å±¤ãèããã¨è¯ãã¨æããã¾ãã
- ã¦ã¼ã¶ã¼ç©ºéã®ã¢ããªã±ã¼ã·ã§ã³
- ã«ã¼ãã«ç©ºéã®ãã¡ã¤ã«ã·ã¹ãã
- æ°¸ç¶ã¹ãã¬ã¼ã¸ããã¤ã¹ï¼ä¸è¬çã«ãã£ã¹ã¯ï¼
ã«ã¼ãã«ç©ºéã®ãã¡ã¤ã«ã·ã¹ãã ããã¦ã¼ã¶ã¼ç©ºéã®ã¢ããªã±ã¼ã·ã§ã³ã¨æ°¸ç¶ã¹ãã¬ã¼ã¸ããã¤ã¹ï¼ãã£ã¹ã¯ï¼ã®éã«ãã£ã¦ããã¡ã¤ã«ã¨ããæ½è±¡åãæä¾ããã¨ããã®ã大ã¾ããªæ§æã«ãªãã¾ãã
以å¾ãç°¡åã®ãããæ°¸ç¶ã¹ãã¬ã¼ã¸ããã¤ã¹ã«ã¤ãã¦ã¯ããã£ã¹ã¯ã¨æ¸ãã¾ãã
ã¤ã³ã¿ã¼ãã§ã¼ã¹
次ã«ãå層ã®éã§ã®ã³ãã¥ãã±ã¼ã·ã§ã³ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã«ã¤ãã¦èãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¡ã¤ã«ã·ã¹ãã éã®ã¤ã³ã¿ã¼ãã§ã¼ã¹
ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¡ã¤ã«ã·ã¹ãã ã¯ã主㫠readãwrite ã·ã¹ãã ã³ã¼ã«ãéãã¦ããã¨ããè¡ãã¾ãã
read 㨠write ã·ã¹ãã ã³ã¼ã«ã®å®ç¾©ã¯ã以ä¸ã®ããã«ãªã£ã¦ãã¾ã
ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count);
ä¸è¨ã®ã·ã¹ãã ã³ã¼ã«ã¯ããããï¼ã¤å¼æ°ããããfd ã¯ãã¡ã¤ã«ãã¹ã¯ãªãã¿ãbuf ã¯ã¦ã¼ã¶ã¼ç©ºéã®ã¡ã¢ãªã¢ãã¬ã¹ãcount ã¯èªã¿æ¸ãã®ãã¤ãæ°ã§ãã
ã·ã¹ãã ã³ã¼ã«èªä½ã®å®ç¾©ã¯ä¸ã®ããã«ãªã£ã¦ãã¾ãããã¢ããªã±ã¼ã·ã§ã³ã¯ã·ã¹ãã ã³ã¼ã«ãéãã¦ãÂ
ãããã¡ã¤ã«ã®ãããç®æããN ãã¤ãèªã¿æ¸ããã¦ãã ãã
ã¨ãããã¨ããã¡ã¤ã«ã·ã¹ãã ã¸ãªã¯ã¨ã¹ããã¦ããã¨èããã¨ä»¥éã®é¨åã«ã¤ãã¦ããããããããããã¾ããã
ãã¡ã¤ã«ã·ã¹ãã ã¨ãã£ã¹ã¯éã®ã¤ã³ã¿ã¼ãã§ã¼ã¹
ãã¡ã¤ã«ã·ã¹ãã ãå«ã OS ã®è¦ç¹ããã¯ããã£ã¹ã¯ã¯é£ç¶çãªåºå®ãµã¤ãºã®ãã¼ã¿ãããã¯ã®éåã¨ãã¦è¦ãã¾ãããã£ã¹ã¯ã¯ãé常ããã¼ã¿ãããã¯ã«å¯¾ãã¦ãããã¯ï¼ã»ã¯ã¿ã¼ï¼çªå·ããã¨ã«èªã¿æ¸ãã®ã¢ã¯ã»ã¹ãè¡ããããã«ãªã£ã¦ãã¾ãã
ãã¡ã¤ã«ã·ã¹ãã ã¯ãã£ã¹ã¯ã«å¯¾ãã¦ãããã¤ã¹ãã©ã¤ããéãã¦èªã¿æ¸ãããªã¯ã¨ã¹ããã¾ããã主ã«ä»¥ä¸ã®ï¼ç¹ãæå®ãã¾ãã
- ãã£ã¹ã¯ä¸ã®ãããã¯ï¼ã»ã¯ã¿ã¼ï¼çªå·
- èªã¿è¾¼ã¿ããªã¯ã¨ã¹ãããå ´åã¯ããã£ã¹ã¯ããèªã¿åºãããã¼ã¿ãé ç½®ãããã¡ã¢ãªä¸ã®ã¢ãã¬ã¹ãæ¸ãè¾¼ã¿ããªã¯ã¨ã¹ãããå ´åã¯ãæ¸ãè¾¼ã¿ãããã¼ã¿ãç½®ãã¦ããã¡ã¢ãªä¸ã®ã¢ãã¬ã¹
- èªã¿æ¸ãã®ãã¼ã¿ã®é·ã
ãã¡ã¤ã«ã·ã¹ãã ã®å½¹å²
éè¦ãªã®ã¯ããã£ã¹ã¯èªä½ã¯ãä¸è¨ã®çªå·ãã¼ã¹ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ããã«ãè¨ãããéãã«ãã¼ã¿ãæå®ãããå ´æã¸èªã¿æ¸ããããã¨ããã§ããªãã®ã§ããã¡ã¤ã«ã¨ããæ¦å¿µãèªèã§ããªããã¨ã§ãã
è¨ãæããã¨ãã¢ããªã±ã¼ã·ã§ã³ãããããã¡ã¤ã«ãèªã¿è¾¼ãã§ãã ããã¨ãããªã¯ã¨ã¹ãããã£ã¹ã¯ã«å¯¾ãã¦ç´æ¥éãããã¦ãããã£ã¹ã¯ããããã¨ãã¼ã¿ã¯ãããã©ãã©ãããã¡ã¤ã«ã®ã©ã®é¨åãããããªãã¨ãããã¨ã«ãªãã¾ãã
æå®ããããã¡ã¤ã«ã®æå®ç®æãããã¼ã¿ãèªã¿åããã¨ãããã¨ãããããã«ã¯ããã£ã¹ã¯ã¨ããé£ç¶çãªãã¼ã¿ãããã¯ã®ãã©ãã«è¦æ±ããããã¼ã¿ãããããã¨ããä½ç½®ã«é¢ããæ å ±ãå¿ è¦ã¨ãªãã¾ãã
ãã¡ã¤ã«ã·ã¹ãã ã®ä¸»ãªä»äºã¯ãã¾ãã«ãã®ããã£ã¹ã¯ä¸ã®ã©ãã«ãªã«ãç½®ãã¦ããããè¨é²ãã¦ãããã¢ããªã±ã¼ã·ã§ã³ã®è¦æ±ã«å¿ãã¦ãã¼ã¿ãèªã¿åºãããããã¯æ¸ãè¾¼ããã¨ãããã¨ã«ãªãã¾ãã
èªã¿æ¸ãã®æµã
ä¸è¨ã®ç¹ãè¸ã¾ãã¦ããã¡ã¤ã«ã·ã¹ãã ã®èªã¿æ¸ãã®å¤§ã¾ããªæµããå³ã«ãã¦ã¿ã¾ãããÂ
å³ä¸ã®çªå·ã«ã¤ãã¦ã¯ããã£ããããå¦çã®é çªãªã®ã§ãããå¦çã®é çªãæã¨å ´åã«ããé¨åãå¤åã«ãããããå³ç¤ºããã¦ããçªå·ã¯å ¨ã¦ã®å ´åã«é©å¿ãããããã§ã¯ãªããã¨ã«ãçæãã ããã
æ¸ãè¾¼ã¿å¦ç
ã¾ããæ¸ãè¾¼ã¿ããè¦ã¦ããã¾ãã
å³ã¯ãã¢ããªã±ã¼ã·ã§ã³ã write ã·ã¹ãã ã³ã¼ã«ãéãã¦ãfile1.txt ã¨ããååã®ãã¡ã¤ã«ã® 300 ãã¤ãç®ãã 5000 ãã¤ãã«ããã¦ã4700 ãã¤ãã®æ¸ãè¾¼ã¿ãè¡ãã¨ãã®ä¾ã示ãã¦ãã¾ãã
å³ä¸ã® fd 㯠file1.txt ã¨ãããã¡ã¤ã«ã®ãã¡ã¤ã«ãã¹ã¯ãªãã¿ã§ããã¨æã£ã¦ãã ããã
ã¾ããå³ä¸ã® lseek ã¯ãæ¸ãè¾¼ã¿ã®éå§ä½ç½®ããã¡ã¤ã«ã® 300 ãã¤ãç®ã«æå®ãã¦ãããã¨ãæ示ããããã«æ¸ãã¦ããã¾ãã
ã¾ããwrite ã·ã¹ãã ã³ã¼ã«ã¯ããã¡ã¤ã«ã·ã¹ãã ã®è¦ç¹ããã¯ãfile1.txt ã¸ã® 300 ãã¤ã ãã 5000 ãã¤ãã¾ã§ã®æ¸ãè¾¼ã¿ãªã¯ã¨ã¹ãã«è¦ãã¾ãï¼å³ä¸çªå·ï¼ï¼ã
write ã·ã¹ãã ã³ã¼ã«ã«ãã£ã¦ãå¦çã®ã³ã³ããã¹ããã«ã¼ãã«ç©ºéã«åãæ¿ããã¨ãã¾ãå§ãã«ããã¼ã¸ãã£ãã·ã¥ã¨å¼ã°ããã«ã¼ãã«ç©ºéå ã®ã¡ã¢ãªé åã«ãã¢ããªã±ã¼ã·ã§ã³ãæ¸ãè¾¼ã¿ããªã¯ã¨ã¹ããã¦ããå¼æ° buf ã§æå®ããããã¼ã¿ãã³ãã¼ãã¾ãããã®å¦çã¯ãå³ä¸çªå·ï¼ã®é¨åã«ãããã¾ãã
ããã§ä¸ã¤ãã¤ã³ãã¯ããã¡ã¤ã«ã·ã¹ãã ã¯å¤ãã®å ´åãï¼ãããã¤ã (å³å¯ã«ã¯ 4096 ãã¤ã) åä½ã§ãã¡ã¤ã«ã®ã³ã³ãã³ããã¼ã¿ã管çãã¦ãã¾ããããã¯ãOS ãã¡ã¢ãªãï¼ãããã¤ããã¨ã«åºåã£ããã¼ã¸ã¨å¼ã°ããåä½ãå ã«ç®¡çãã¦ãããã¨ã«èµ·å ãã¦ããããã«æããã¾ããÂ
ä»åã®ä¾ã§ã¯ãä¸ã¤ç®ã®ãã¼ã¸ãã£ãã·ã¥ã®ãã¼ã¸ã¯ 300 ãã¤ãç®ããã4095 ãã¤ãç®ã¾ã§ãä¿æï¼èµ¤ãé¨åï¼ãäºã¤ç®ã®ãã¼ã¸ã¯ã4096 ãã¤ãç®ãã 5000 ãã¤ãç®ã«ããã¦ã®ãã¼ã¿ï¼éãé¨åï¼ãä¿æãã¾ãããã®ã¨ããã¢ããªã±ã¼ã·ã§ã³å´ã§ã¯ãï¼ãããã¤ãã®ã¢ã©ã¤ã³ã¡ã³ãã«å¯¾ãã¦é æ ®ããå¿ è¦ã¯ããã¾ããã
ããã¾ã§ã write ã·ã¹ãã ã³ã¼ã«ã§è¡ãããå¦çã§ãå³ä¸ã®çªå·ï¼ä»¥éã¯ãå®è£ 次第ã§ãããå¿ ãããã·ã¹ãã ã³ã¼ã«ã®ä¸ã§å®è¡ããã¾ããã
å³ä¸ã®ï¼ã¨ï¼çªã®å¦çã«é¢ãã¦ã¯ãã¢ããªã±ã¼ã·ã§ã³ã¨ãã¡ã¤ã«ã·ã¹ãã éã®ããã¨ãã§ãããï¼çªä»¥éã¯ããã¡ã¤ã«ã·ã¹ãã ã¨ãã£ã¹ã¯éã®ã³ãã¥ãã±ã¼ã·ã§ã³ã§ãã
å³ä¸çªå·ï¼ä»¥éã®ãã¡ã¤ã«ã·ã¹ãã ã¨ãã£ã¹ã¯ã¨ã®ããã¨ããç¹ã«æ¸ãè¾¼ã¿ã¯ãå¤ãã®å ´åãã¢ããªã±ã¼ã·ã§ã³ã¨ã¯ç¬ç«ãããã«ã¼ãã«ã¹ã¬ããã§å®è£ ãããã¢ããªã±ã¼ã·ã§ã³ã®å¦çã¨ã¯éåæã§ãã£ã¹ã¯ã®æ¸ãè¾¼ã¿ãè¡ããã¾ãããã£ã¹ã¯ã¸ã®æ¸ãè¾¼ã¿ã¯ä¸è¬çã«ã¨ã¦ãæéãããããããæ¸ãè¾¼ã¿ãå¤é¨ã®ã¹ã¬ããã¸ä»»ãããã¨ã§ãã¢ããªã±ã¼ã·ã§ã³ã¸ã®ãã£ã¹ã¯æ¸ãè¾¼ã¿ã®é 延ã®å½±é¿ãæãããã¨ããæå³ãããã¾ãã
æ¸ãè¾¼ã¿ã¹ã¬ããã¯ãå®æçã«ï¼ä¾ãã°ï¼ï¼ç§ãã¨ï¼ããããã¯ãã¼ã¸ãã£ãã·ã¥ãæ°ããæ¸ãè¾¼ã¿ãã¼ã¿ã§ãã£ã±ãã«ãªã£ã¦ãã¾ã£ãå ´åã« OS ã«ãã£ã¦æ¸ãè¾¼ã¿ãå§ããããã«ä¿ããã¾ãããã®ã¨ãã«ãåãã¦å³ä¸ï¼çªã®å¦çãéå§ããã¾ãã
æ¸ãè¾¼ã¿ã¹ã¬ãããã¾ãå§ãã«ãã¹ããã¨ã¯ãæ°ãããã¼ã¿ããã£ã¹ã¯ã®ã©ãã«æ¸ãè¾¼ãã決ãããã¨ã§ãããã®æ¸ãè¾¼ã¿ä½ç½®ã®æ±ºå®ã¯ãã¡ã¤ã«ã·ã¹ãã ã®è¨è¨ã«ããã¦é常ã«éè¦ã§ãæ§è½ãæ©è½ã«å¤§ããå½±é¿ãããã¾ãã ï¼è©³ç´°ã¯å¥éè¨äºãæ¸ãäºå®ã§ããï¼
ä»åã®å³ã®ä¾ã§ã¯ããã¡ã¤ã«ã·ã¹ãã ã¯ããªãã¨ãªããã¼ã¸ãã£ãã·ã¥ã®ï¼ãã¼ã¸ç®ã300 ãã¤ããã 4095 ãã¤ãç®ã¾ã§ã¯ãã£ã¹ã¯ä¸ã®ãããã¯çªå· 400 ã¸ãï¼ãã¼ã¸ç®ã¯ 950 ã¸æ¸ããã¨ã«ããããã§ãã
ããã§éè¦ãªã®ãããã¡ã¤ã«ã·ã¹ãã ã¯ããã®ãfile1.txt ã®ï¼ãã¼ã¸ç®ï¼æåã®ï¼KBï¼ããããã¯çªå· 400ãï¼ãã¼ã¸ç®ï¼ï¼ãããã¤ãããï¼ãããã¤ãã«ããã¦ï¼ããããã¯çªå· 950 ã«æ¸ããã¦ãããã¨ããæ å ±ãä¿æããªããã°ãªããªãã¨ãããã¨ã§ãããã®ãããªæ å ±ã¯ã¡ã¿ãã¼ã¿ã¨å¼ã°ããã¡ã¢ãªï¼ DRAM ) ä¸ã®ãã¼ã¿ãæ¶ãã¦ãã¾ã£ãåèµ·åå¾ã«ãã¢ã¯ã»ã¹å¯è½ãªããã«ããã¡ã¤ã«ã®ã³ã³ãã³ãããã£ã¹ã¯æ¸ãè¾¼ã¾ããã¨ãã«ãä¸ç·ã«æ¸ãè¾¼ã¾ãã¾ãããã®ã¡ã¿ãã¼ã¿ã®ç®¡çã¯ããã¡ã¤ã«ã·ã¹ãã ã®è¨è¨ã«ããã¦é常ã«éè¦ã§é£ããé¨åã«ãªãã¾ããï¼è©³ç´°ã¯è¤éãªã®ã§ããã¡ããå¥ã®è¨äºã¨ãã¦æ¸ããã¨æã£ã¦ãã¾ããï¼
æ¸ãè¾¼ã¿å ã決å®ãããã次ã¯ãããã¤ã¹ãã©ã¤ããéãã¦ããã¼ã¸ãã£ãã·ã¥ä¸ã®ãã¼ã¿ããã£ã¹ã¯ã¸æ¸ãã¦ãããããã«ãªã¯ã¨ã¹ããéä¿¡ãã¾ãï¼å³ä¸çªå·ï¼ï¼ã
ãã®å¾ããªã¯ã¨ã¹ãã«å¿ãã¦ããã¼ã¿ãæå®ãããã£ã¹ã¯ä¸ã®ä½ç½®ã«æ¸ãè¾¼ã¾ãã¾ãï¼å³ä¸çªå·ï¼ï¼ã
ããã¾ã§ãããã¾ããªãã¦ã¼ã¶ã¼ç©ºéã®ãã¼ã¿ããã£ã¹ã¯ã¾ã§éãå±ããããã¾ã§ã®æµãã§ãã
çç¥ããç¹ã¨ãã¦ãå³ã® write ã·ã¹ãã ã³ã¼ã«ã®ä¾ã¯ããã¼ã¸ã®ä¸é¨ã«ããæ¸ãè¾¼ã¿ãè¡ããªããããå®éã¯ããã¼ã¿ããã¼ã¸ãã£ãã·ã¥ã«ãªãã£ãå ´åã0 ã 299 ãã¤ãç®ã¨ã5000 ã 8191 ãã¤ãç®ã¾ã§ããã¼ã¸ãã£ãã·ã¥ã¸ãã¼ãããããã«ãå³ä¸çªå·ï¼ã¨ï¼ã®å¦çã®éã«ãã£ã¹ã¯ããã®èªã¿è¾¼ã¿ãè¡ããã¾ãããã¡ã¤ã«ãµã¤ãºãï¼ã§å¯¾å¿ãããã¼ã¿ããã£ã¹ã¯ä¸ã«ãªããã¨ãæãããªå ´åã¯ãã®éãã§ã¯ããã¾ããããããã¯ãæ¸ãè¾¼ã¿åã®ãã¡ã¤ã«ãµã¤ãºãï¼ãã¼ã¸ã«åã¾ã£ã¦ããå ´åã¯ãèªã¿è¾¼ã¿ã¯æåã®ï¼ãã¼ã¸ã®ã¿ã ãã«ãªãã¾ããã¾ããä»åã®ä¾ã®ããã«æ¸ãè¾¼ã¿ããã¼ã¸ã®ä¸é¨ã§ã¯ãªããï¼ãã¼ã¸å ¨ä½ãä¸æ¸ãããå ´åã«ã¯ããã®èªã¿è¾¼ã¿ã¯ä¸è¦ã«ãªãã¾ãã
èªã¿è¾¼ã¿å¦ç
次ã«ãèªã¿è¾¼ã¿å¦çãè¦ã¦ããã¾ãã
ä»åº¦ã®ä¾ã§ã¯ãã¢ããªã±ã¼ã·ã§ã³ã read ã·ã¹ãã ã³ã¼ã«ã使ã£ã¦ãå ã»ã© file1.txt ã¸æ¸ãè¾¼ãã 300 ã 5000 ãã¤ãç®ã¾ã§ã®ãã¼ã¿ãèªã¿è¾¼ã¿ã¾ããæåã®æ®µéã§ã¯ãã¼ã¸ãã£ãã·ã¥ã«ãã¼ã¿ããªãã¨æã£ã¦è¦ã¦ãã ããã
ã¾ããèªã¿è¾¼ã¿ããªã¯ã¨ã¹ãããããã«ã¢ããªã±ã¼ã·ã§ã³ã¯ read ã·ã¹ãã ã³ã¼ã«ãçºè¡ãã¾ããï¼å³ä¸ã®çªå·ï¼ã«ãããã¾ããï¼
å®è¡ã³ã³ããã¹ããã«ã¼ãã«ç©ºéã¸ç§»è¡ãããã¡ã¤ã«ã·ã¹ãã ã¯ã対å¿ãããã¼ã¿ãã©ãã«ãããã«ã¤ãã¦èãã¾ããå½ããåã§ããããã¼ã¿ã¯ãã¡ã¤ã«ã·ã¹ãã ãèªåã§æ¸ãè¾¼ãã å ´æã«ããã¾ããæ¸ãè¾¼ã¿å´ã®ä¾ã§ã¯ã300 ã 4095 ãã¤ãç®ã¾ã§ã¯ããã£ã¹ã¯ä¸ã®ãããã¯çªå· 400 çªã«ã4096 ã 5000 ãã¤ãã«ããã¦ã¯ãããã¯çªå· 950 ã«æ¸ãè¾¼ã¿ã¾ããããã®ä½ç½®ã«é¢ããæ å ±ã¯ããã¡ã¤ã«ã·ã¹ãã ãã¡ã¿ãã¼ã¿ã¨ãã¦ä¿æãã¦ããããã®ããã«ãèªã¿è¾¼ã¿ã®éã«ã¯åç §ããã¾ããï¼ä¿æã®å½¢å¼çã«ã¤ãã¦ã¯å¥ã®è¨äºã«åããäºå®ã§ããï¼
ã¡ã¿ãã¼ã¿ãåç §ãããã¨ã«ãã£ã¦ããã¡ã¤ã«ã·ã¹ãã 㯠file1.txt ã® 300 ã 4095 ãã¤ãç®ã¾ã§ã¯ããã£ã¹ã¯ä¸ã®ãããã¯çªå· 400 çªã«ã4096 ã 5000 ãã¤ãã«ããã¦ã¯ãããã¯çªå· 950 ã«ãããã¨ããããã¾ããããããå³ä¸ï¼çªã§ãã
ãã¼ã¿ã®å ´æãããã£ãã®ã§ãããã¤ã¹ãã©ã¤ããéãã¦ããã£ã¹ã¯ããã®èªã¿åºãããªã¯ã¨ã¹ããã¾ãï¼å³ä¸ï¼çªï¼ããã®ã¨ããã¡ã¢ãªä¸ã®èªã¿åºãå ã¨ãã¦ãã¼ã¸ãã£ãã·ã¥ãï¼ãã¼ã¸åæ°ãã«ç¢ºä¿ãã¦ããã¾ãã
ãã£ã¹ã¯ããã®èªã¿åºããªã¯ã¨ã¹ãã®çµæããã¼ã¿ã¯ããã¼ã¸ãã£ãã·ã¥ã¸èªã¿åºããã¾ãï¼å³ä¸ï¼çªï¼ã
æå¾ã«ããã¡ã¤ã«ã·ã¹ãã ã¯ããã¼ã¸ãã£ãã·ã¥ã«èªã¿è¾¼ã¾ãããã¼ã¿ããread ã·ã¹ãã ã³ã¼ã«ã®å¼æ° buf ã§æå®ãããã¦ã¼ã¶ã¼ç©ºéã®ã¡ã¢ãªã«ã³ãã¼ãã¾ãï¼å³ä¸ï¼çªï¼ã
ããã«ãã£ã¦ãã¢ããªã±ã¼ã·ã§ã³ã¯ããã£ã¹ã¯ã«ä¿åããããã¼ã¿ãåãåºããã¨ãã§ãã¾ããã
ããå°ãã ãå³å¯ãªèªã¿è¾¼ã¿ã®æµã
ããå°ãã ãå³å¯ã«èªã¿è¾¼ã¿å¦çã®æµããæ¸ãã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
ãã¤ã³ãã¨ãã¦ããã¼ã¸ãã£ãã·ã¥ã«ååã®èªã¿è¾¼ã¿ãããã¯æ¸ãè¾¼ã¿ã«ãã£ã¦ããã§ã«å¿ è¦ãªãã¼ã¿ããã£ãå ´åã«ã¯ãread ã·ã¹ãã ã³ã¼ã«ã¯ãã¼ã¸ãã£ãã·ã¥ãããã¼ã¿ãã¦ã¼ã¶ã¼ç©ºéã¸ã³ãã¼ããã ãã§å®äºãã¾ãããã®å ´åãread ã·ã¹ãã ã³ã¼ã«ã®ä¸ã§ããã£ã¹ã¯ããã®èªã¿åãã¯ä¸è¦ãªã®ã§ããã£ã¹ã¯ã¸ãã¼ã¿ãèªã¿åãã«è¡ã£ãå ´åã¨æ¯ã¹ã¦ããªãé 延ãç縮ããã¾ãã
ç©çã¡ã¢ãªã®ãµã¤ãºã大ããã»ã©ããã¼ã¸ãã£ãã·ã¥ãå¤ãç¨æã§ããããã大ãã容éã®ã¡ã¢ãªãè³¼å ¥ããã¨ããã¡ã¤ã«ããã®èªã¿è¾¼ã¿ã®æéãç縮ã§ããå ´åãå¢ããå¯è½æ§ãããã¾ãã ç¹ã«ããã£ã¹ã¯ãé ãã»ã©å¹æãé«ããã§ãã
ãã®ä»ã®æ å ±
- ãã¡ã¤ã«ã·ã¹ãã ã®å¤ãã¯ããã¼ã¸ãã£ãã·ã¥ãçµç±ããªãã§ãã£ã¹ã¯ã¸ã®èªã¿æ¸ããè¡ããªãã·ã§ã³ï¼O_DIRECTï¼ãæä¾ãã¦ãã¾ãã
- ãã¼ã¸ãã£ãã·ã¥ã¯ãä»ã®ç®æã§ã®ã¡ã¢ãªä½¿ç¨éã¨ä½¿ç¨é »åº¦ã«å¿ãã¦è§£æ¾ããã¾ããã·ã¹ãã å ¨ä½ã®ã¡ã¢ãªä½¿ç¨éãåè¿«ãã¦ããã¨ãOS ã¯ãã¼ã¸ãã£ãã·ã¥ãç©æ¥µçã«è§£æ¾ãããã¨ãã¾ãã
- fsync ã®ãããªã·ã¹ãã ã³ã¼ã«ãå©ç¨ããã¨ãã¢ããªã±ã¼ã·ã§ã³ã¯æ示çã«ãã£ã¹ã¯ã¸ã®æ¸ãåºãããã¡ã¤ã«ã·ã¹ãã ã¸ãªã¯ã¨ã¹ãã§ãã¾ãã
ã¾ã¨ã
- ãã¡ã¤ã«ã·ã¹ãã ã¯ã¢ããªã±ã¼ã·ã§ã³ã¨ãã£ã¹ã¯ã仲ä»ãã¦ããã¡ã¤ã«ã®æ¦å¿µãé£ç¶çãªãã¼ã¿ãããã¯ã®éåã§ãããã£ã¹ã¯ã®ä¸ã«å®è£ ããã
- write ã·ã¹ãã ã³ã¼ã«ã¯ãåºæ¬çã«ã¦ã¼ã¶ã¼ç©ºéããã«ã¼ãã«ç©ºéã®ã¡ã¢ãªã³ãã¼ã§å®çµããå¤ãã®å ´åããã£ã¹ã¯ã¸ã®æ¸ãè¾¼ã¿ã¯éåæã§è¡ãããã
- read ã·ã¹ãã ã³ã¼ã«ã¯ãèªã¿è¾¼ã¿ãããã¼ã¿ããã§ã«ãã¼ã¸ãã£ãã·ã¥ã«ããã°ãã«ã¼ãã«ç©ºéããã¦ã¼ã¶ã¼ç©ºéã¸ã®ã¡ã¢ãªã³ãã¼ã ãã§å®çµãããããã¼ã¸ãã£ãã·ã¥ã«ãã¼ã¿ããªããã°ãã£ã¹ã¯ããèªã¿è¾¼ãã