使用 SystemTap 調試內核
#!/usr/bin/env stap## display the top 10 syscalls called in last 5 seconds#global syscallsfunction print_top () {cnt=0log (SYSCALLttttCOUNT)foreach ([name] in syscalls-) {printf(%-20stt%5dn,name, syscalls[name])if (cnt++ == 10)break}printf(--------------------------------------n)delete syscalls}probe syscall.* {syscalls[probefunc()]++}probe timer.ms(5000) {print_top ()}
它的輸出結果一目了然:

看看是誰在偷偷動我的文件
有時候,我們如果中了惡意的病毒軟件,會發現某些文件莫名其妙的被修改,下面這個例子可以幫你監視誰在修改你的文件。
#!/usr/bin/env stap## monitor who is messing my file of secrets#probe generic.fop.open {if(filename == secrets)printf(%s is opening my file: %sn, execname(), filename)}
我們運行這個腳本,在另外一個窗口做一些操作,來看看它的輸出結果:

打印ANSI字符串
SystemTap不僅僅是一個簡單的調試工具,強大的腳本語言能力讓它同樣能做一些有趣的事情,
下面這個例子就可以對輸出的字符進行美化:
#!/usr/bin/env stap## print colorful ANSI strings#probe begin {printf(a \ b |);for (c = 40; c 48; c++)printf( %d , c);printf(12);for (l = 0; l 71; l++)printf(-);printf(12);for (r = 30; r 38; r++)for (t = 0; t 2; t++) {printf(%d |, r);for (c = 40; c 48; c++)printf( 主站蜘蛛池模板: 湖北省| 晋城| 文昌市| 平凉市| 区。| 天等县| 娄烦县| 阳谷县| 理塘县| 乌什县| 宝坻区| 玉山县| 武穴市| 连平县| 贞丰县| 玛纳斯县| 临江市| 望城县| 东山县| 澜沧| 大方县| 南漳县| 安达市| 邹城市| 祁门县| 鲜城| 博湖县| 新郑市| 普安县| 石首市| 和平区| 嘉鱼县| 皋兰县| 杭州市| 石阡县| 临沧市| 思茅市| 元氏县| 珲春市| 绥芬河市| 巴林左旗|