使用静态库链接程序

摘要: 转载:http://www.708luo.com/?p=21先关注两个gcc编译选项:-c 编译且汇编,但是不链接-S 只编译,不汇编也不链接-c选项产出的就是经常看到的.o文件,也是一般用来创建静态库的文件。用如下的命令可以将多个.o文件打包为一个静态库文件:ar crs libtest.a src/test1.o src/test2.o现在完成了静态库创建工作,我们怎么在链接一个可执行程序的时候使用这个静态库呢?有三种方式:1. gcc -o test main.c libtest.a2. gcc -o test main.c –ltest –L./3. gcc -o test main. 阅读全文
posted @ 2012-06-06 13:57 悟空不悟空 阅读(6004) 评论(1) 推荐(0) 编辑

linux获取当前执行脚本

摘要: 原文链接今天遇到一个需求,获取当前执行脚本。如果是sh test.sh或者./test.sh的运行方式,那么很简单,直接使用$0就可以了。那么如果是source test.sh或者. ./test.sh的方式运行呢?$0就变成了”-bash”了。google了一下,这个时候就需要使用$BASH_SOURCE了。(bash版本>=3.0)[u1@localhost test]$ sh test.sh test.shtest.sh[u1@localhost test]$ source test.sh -bashtest.sh[u1@localhost test]$ cat test.sh e 阅读全文
posted @ 2012-06-01 12:04 悟空不悟空 阅读(1939) 评论(0) 推荐(0) 编辑

google cpu profiler二进制结果读取

摘要: 原文地址:http://www.708luo.com/?p=18最近一段时间在google cpu profiler做性能热点采样。用过的人都知道,cpu profiler产出的原始结果是二进制存储的。一般是得到这个结果再使用pprof工具去转化为人可读的文本形式的结果或者图片形式的结果。但是最近有一些需求:1. 对两个版本的profiler结果做比较2. 根据历史数据,对单次profiler结果做一些分析,提示一些可以优化的点要实现这两个功能,如果是基于pprof转化过的数据进行处理,总会有一些获取不到的信息。所以,最好是基于profiler的原始数据来完成上述的功能。因为profiler的 阅读全文
posted @ 2012-05-28 21:12 悟空不悟空 阅读(985) 评论(0) 推荐(0) 编辑

python中如何中止一个线程

摘要: 转载自:http://www.708luo.com/?p=30class KillableThread(threading.Thread): """A subclass of threading.Thread, with a kill() method.""" def __init__(self, *args, **keywords): threading.Thread.__init__(self, *args, **keywords) self.killed = False def start(self): "" 阅读全文
posted @ 2012-03-29 21:18 悟空不悟空 阅读(1906) 评论(0) 推荐(0) 编辑