• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            newplan

            阿基米德在洗澡時發現浮力原理,高興得來不及穿上褲子,跑到街上大喊:Eureka(我找到了)。
            posts - 39, comments - 26, trackbacks - 0, articles - 4
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            同步寫與異步寫文件實現

            Posted on 2007-11-21 18:45 山泉彎延 閱讀(1223) 評論(0)  編輯 收藏 引用 所屬分類: UNIX Programming
            /*
             07.11.20 于海韻
            */
            #
            include  "sys/times.h"
            #include "apue.h"
            #include "fcntl.h"

            clock_t times(struct tms *buf);

            static void pr_times(clock_t real 
            ,struct tms *tmsstart, struct tms *tmsend);

            int main(int argc, char *argv[])
            {
              struct tms tmsstart
            ,tmsend;
             
              clock_t  start
            ,end;
             
              off_t excursion;
             
              
            if((excursion=lseek(0,0,SEEK_END))==-1)printf("can not seek!\n");
             
              char buf[excursion];
             
              
            /*printf("excutsion ==#%d\n",excursion);*/
              
            int outfile_fd;/*out file descrite tag */
             
              lseek(
            0,0,SEEK_SET);/*it is very importent  to go back  to the beginning of input file!*/
             
              
            if(read(0,buf,excursion)==0)printf("read OK!\n");
              
            /* buf[excursion]='\0';*/
              
            if(argc==3  &&  strcmp(argv[2],"sync")==0)
                  { 
            if(( outfile_fd=open(argv[1],O_RDWR|O_CREAT|O_SYNC,0666))<0)err_sys("creat error");}
                
            else if(argc==2)
                   {
            if (( outfile_fd=open(argv[1],O_RDWR|O_CREAT,0666))<0)err_sys("creat error");}
                
            else{printf("para error!\n");exit(1);}
                long size
            =1024
                fflush(stdin);
                
            printf("BUFFSIZE  USER CPU  SYSTEM CPU  REAL TIMES  CIRCLE TIMES\n");
                
            int  n;
                
            int t;
                char 
            *p=buf;
                long  redo_count;
            /*re do copy times*/ 

              
            do
                  
            if((start=times(&tmsstart))==-1)err_sys("times error");
                  redo_count
            =0;/*it is very import to set the counter zero at every circle */
                  t
            =1;/*it is use in the inside while */
                  
            while((n=write(outfile_fd,p,size))==size)
                          {   p
            +=size;/*the begin buf must increase every time*/
                              redo_count
            ++;/*count how many times circle do*/
                              t
            =size*redo_count;/*one tag to count how many charaters we have travered*/
                              
            /* printf("excursion==%d  t==%d   excursion-t==%d  size==%d\n",excursion,t,excursion-t,size);*/
                              
            if((excursion-t)<size)break;
                          }
                  
            if(excursion-t>0)
                     
            if(write(outfile_fd,p,excursion-t)!=(excursion-t))err_sys("read error");
                  
            if((end=times(&tmsend))==-1)err_sys("times error");
                  
            printf("%7ld",size);
                  pr_times(end
            -start,&tmsstart,&tmsend);
                  
            printf("%7ld\n",redo_count);
                  lseek(outfile_fd
            ,0,SEEK_SET);/*let the outfile pointer go back to the beginning of outfile!*/
                  p
            =buf;/*let p return to the beginning of buf;*/
                 
            /* printf("size=%d  excursion=%d\n",size,excursion);*/
                 } 
            while((size*=2)<=excursion);
              
            return 0;
            }
            static void
            pr_times(clock_t real 
            ,struct tms *tmsstart,struct tms *tmsend)
            {static long clktck
            =0;
            if(clktck==0)
             
            if((clktck=sysconf(_SC_CLK_TCK))<0)
                
            printf("sysconf error");

            printf("   %2.5f",(tmsend->tms_utime-tmsstart->tms_utime)/(double)clktck);
            printf("   %2.5f",(tmsend->tms_stime-tmsstart->tms_stime)/(double)clktck);
            printf("     %2.5f    ",real/(double)clktck);

             

            国产婷婷成人久久Av免费高清| 免费精品久久久久久中文字幕| 国内精品伊人久久久久777| 一级a性色生活片久久无| 国产激情久久久久久熟女老人 | 精品久久无码中文字幕| 国产成人久久精品激情| 国产精品免费久久| 亚洲综合熟女久久久30p| 久久香蕉国产线看观看乱码| 亚洲国产成人久久综合一区77| 久久亚洲欧美国产精品| 人妻无码精品久久亚瑟影视| 久久天堂AV综合合色蜜桃网| 久久99久久成人免费播放| 国产三级久久久精品麻豆三级| 亚洲国产成人乱码精品女人久久久不卡| 欧美精品久久久久久久自慰| 亚洲国产小视频精品久久久三级 | 国产毛片久久久久久国产毛片| 亚洲精品国产字幕久久不卡| 国产精品无码久久四虎| 97精品久久天干天天天按摩| 久久久久亚洲AV片无码下载蜜桃| 久久亚洲国产欧洲精品一| 亚洲国产精品成人久久| 久久久久久毛片免费看 | 91麻精品国产91久久久久| 亚洲国产精品无码久久一区二区| 久久国产免费直播| 久久精品视频91| 国产精品免费久久| 久久综合成人网| 欧美精品福利视频一区二区三区久久久精品 | 精品国产乱码久久久久久1区2区| 合区精品久久久中文字幕一区| 精品多毛少妇人妻AV免费久久| 97精品久久天干天天天按摩| 久久久久亚洲AV成人片| a高清免费毛片久久| 97精品国产91久久久久久|