私の

  
Unixの下で  

自分で用意したファイルの内容と一緒に大きなテキストファイルをコピーします。要求は10M以上のテキストです。

(テキストを書くことができます。それからcatは繰り返し展開されたテキストを追加することができます)

プログラムの形式:入力コマンドとパラメータ$ my_copy from_name to_name bufsize(number)

bufsize統計、my_copyの実行時間は、分析結果を示し、そしてその理由を分析します。

my_copyを実行するときは、vmstat 1の出力を同期的に収集してlog.txtにリダイレクトする必要があります。

bufsize:1 3264 1282565121024

ヒント:このプログラムはWindowsと一緒には開発できません。

#include< stdio.h> #include< sys /types.h> #include< sys /stat.h> #include< fcntl.h> #include< sys /time。 h> #include< unistd.h>

void tv_sub(struct timeval * end、struct timeval * begin)//時間差を計算し、結果を最後に格納する{if((end-> tv_usec- =)開始 - > tv_usec)< 0){ - 終了 - > tv_sec;終了 - > tv_usec + = 1000000;}終了 - > tv_sec - =開始 - > tv_sec;}

int Main(int argc、char * argv []){typedef struct timeval TIME; TIME開始、終了; gettimeofday(開始、NULL);

int f_read、f_write、num; const int BUFSIZE = atoi( Argv [3]); char buf [BUFSIZE];

if(argc!= 4){printf("使用方法:my_readファイル名1ファイル名2 bufsize \\ n"); exit(1);}

if((f_read = open(argv [1]、O_RDONLY))< 0){printf( "ファイル%sを開けません\\ n"; argv [1]);}

if((f_write = open(argv [2]、O_WRONLY

Copyright © Windowsの知識 All Rights Reserved