|

楼主 |
发表于 2003-12-29 21:22:37
|
显示全部楼层
最初由 x11 发表
版主说的是
不过随便找个人来你放心么,哈哈
我晕~~~~~~~
请看看这个程序,目的是要是文件被访问了三次就退出,执行是有N多输出,怎么让它没有多余的输出呢?
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 time_t GET_ACCESS_TIME ()
14 {
15 struct stat buf;
16 if( stat( "/root/fstab", &buf ) != -1 ) {
17 printf( "File last access time = %d\n", buf.st_atime );
18 } /* time_t st_atime time when file date was last access */
19 return (buf.st_atime);
20 }
21 int main ()
22 {
23 int count=0;
24 time_t access_old,access_new;
25 access_old=GET_ACCESS_TIME();
26 while (1) {
27 access_new=GET_ACCESS_TIME();
28 if( access_old != access_new) {
29 ++count;
30 access_old=access_new;
31 sleep (0.1);
32 }
33 if ( count == 3 ) {
34 printf("the /root/fstab already access 3 time !\n");
35 return (access_new);
36 }
37 }
38 exit (0);
39 }
运行时出现很多这样的输出:
File last access time = 1072733084
File last access time = 1072733084
File last access time = 1072733084
File last access time = 1072733084
我想不要这些。 |
|