妙用truss破解df命令

在HPUX,Redhat,Solaris各平台下磁盘分区信息的取得主要采用df命令。通过truss调试命令可以探索df命令实现的内部机理。

命令格式:
truss -l -D -f -t <syscall> -o <log_file> <command>
-c : 显示全面统计结果
-l : 显示线程号
-D : 显示系统调用完成花费的时间
-f :除了跟踪当前进程外,还跟踪其子进程
-o file :将输出信息写到文件file中,而不是显示到标准错误输出(stderr)
-t syscall: 指定要跟踪的系统调用
-p pid :绑定到一个由pid对应的正在运行的进程。此参数常用来调试后台进程


执行命令:
# truss -o trace.log df

分析结果:
df命令执行过程如下
1. 读取 /etc下的配置文件,取得挂载路径名和文件系统名:
HPUX: /etc/mnttab
Linux: /etc/mtab
Solaris: /etc/mnttab

2.调用函数 statvfs64,根据挂载路径名取得文件系统信息:
#include <sys/types.h>
#include <sys/statvfs.h>
int statvfs (const char *path, struct statvfs *buf);

猜你喜欢

转载自tianyihuyidao9.iteye.com/blog/1490151