易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux下时间度量的深入分析

一)ANSI clock函数
1)概述:
clock 函数的返回值类型是clock_t,它除以CLOCKS_PER_SEC来得出时间,一般用两次clock函数来计算进程自身运行的时间.
ANSI clock有三个问题:
1)如果超过一个小时,将要导致溢出.
2)函数clock没有考虑CPU被子进程使用的情况.
3)也不能区分用户空间和内核空间.
所以clock函数在linux系统上变得没有意义.
2)测试
编写test1.c程序,测试采用clock函数的输出与time程序的区别.
vi test1.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main( void )
{
   long i=1000L;
   clock_t start, finish;
   double  duration;
   printf( "Time to do %ld empty loops is ", i );
   start = clock();
   while (--i){
    system("cd");
   }
   finish = clock();
   duration = (double)(finish - start) / CLOCKS_PER_SEC;
   printf( "%f seconds\n", duration );
   return 0;
}
gcc test1.c -o test1
time ./test1
Time to do 1000 empty loops is 0.180000 seconds
real    0m3.492s
user    0m0.512s
sys     0m2.972s
3)总结:
(1)程序调用 system("cd");,这里主要是系统模式子进程的消耗,test1程序不能体现这一点.
(2)0.180000 seconds秒的消耗是两次clock()函数调用除以CLOCKS_PER_SEC.
(3)clock()函数返回值是一个相对时间,而不是绝对时间.
(4)CLOCKS_PER_SEC是系统定义的宏,由GNU标准库定义为1000000.
二)times()时间函数
1)概述:
原型如下:
clock_t times(struct tms *buf);
tms结构体如下:
strace tms{
 clock_t tms_utime;
 clock_t tms_stime;
 clock_t tms_cutime;
 clock_t tms_cstime;
}
注释:
tms_utime记录的是进程执行用户代码的时间.
tms_stime记录的是进程执行内核代码的时间.
tms_cutime记录的是子进程执行用户代码的时间.
tms_cstime记录的是子进程执行内核代码的时间.
2)测试:
vi test2.c
#include <sys/times.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
static void do_cmd(char *);
st


相关文档:

Red Hat Linux 学习笔记


Red Hat Linux 学习笔记
 
1.       在linux 上和其他计算机共享文件,需要在linux上搭建ftp server (vsftp)
2.       启动linux上的ftp server 使用命令:service vsftpd start
3.       ......

在linux环境下安装oracle 11g database方法指导

说明:
大家好,我用的是虚拟机下linux环境进行安装的oracle 11g 数据库,有些不妥的地方请多多指教。
首先要参考原版的安装使用说明文档,根据上面的描述的要求进行安装操作。
 
如下是手动操作的方法:
 
一.检查linux环境RPM包的是否完全安装,并记录缺少的RPM包文件并进行安装。
[root@mylinux ~]# r ......

Linux查看硬件信息及驱动设备相关整理


================================================================================
                      =Linux查看硬件信息及驱动设备相关整理=                       
============ ......

Linux挂载网络文件夹(简单NFS配置)

###########################################
###  挂载网络文件夹  ###
###########################################
NFS说明
=======
NFS是Net File System的简写,即网络文件系统.
NFS允许一个系统在网络上与它人共享目录和文件。通过使用NFS,用户和程序可以象访问本地文件一样访问远端系统上的文件。 ......

Linux下查看cpu类型、内存大小、硬盘大小类型等

CPU查看:
1、  # dmesg | grep CPU
  Initializing CPU#0
  CPU: Trace
cache: 12K uops
  CPU: L1 I-cache: 0K, L1 D-cache: 16K
  CPU: L2
cache: 256K
  Intel machine check reporting enabled on CPU#0.
  
CPU: After generic, caps: bfebfbff 00000000 00000000 00000000
  
CPU ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号