《Linux高级程序设计》2nd version,杨宗德
1. 杂问
Q:我们的系统如何保持其OS可移植性的?使用ANSI库吗?
2. extern
好像只有变量需要extern声明,function不需要,如下例:
[root@frank extern]# cat file.c
#include <stdio.h>
int i=0;
void test() {
printf("in function: i=%d/n", i);
}
[root@frank extern]# cat test.c
#include <stdio.h>
//extern i;
int main() {
// printf("in main, i=%d/n", i);
test();
return 0;
}
T:Got it ! 函数的默认storage type为extern,所以无需显式声明。
3. valgrind,内存调试工具
[root@frank valgrind]# cat sample.c
#include <stdio.h>
int main() {
int i[5];
if (i[0] == 0) {
i[1]=1;
}
return 0;
}
[root@frank valgrind]# valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./sample
==3545== Memcheck, a memory error detector.
==3545== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==3545== Using LibVEX rev 1658, a library for dynamic binary translation.
==3545== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==3545== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==3545== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==3545== For more details, rerun with: -v
==3545==
==3545== Conditional jump or move depends on uninitialised value(s)
==3545== at 0x804836A: main (in /study/books/alp2/valgrind/sample)
==3545==
==3545== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 1)
==3545== malloc/free: in use at exit: 0 bytes in 0 blocks.
==3545== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==3545== For counts of detected errors, rerun with: -v
==3545== All heap blocks were freed -- no leaks are possible.
4. 文件访问
缓冲文件访问会有用户态与内核态的切换,频繁使用对程序性能影响较大! Q:How ??? 2011/12/19
文件流指针FILE与文件描述符fd区别巨大,一个是库,一个是系统调用,对应于用户态及内核态的不同!
POSIX标准文件IO管理,open,close,read,write
5. 进程
Q:孤儿进程与僵尸进程? 2011/12/19