2014年2月12日
摘要: 1.首先是获取当前程序的pid和ppid(parent pid)#include#include int main() { printf("the pid of this program is %d\n",(int)getpid()); printf("the parent pid is %d\n",(int)getppid()); return 0; }执行过程中发现,多次执行后pid一般会变化,而ppid一般不会变,2.在程序中创建新进程可以有两种方式,一种是直接通过system函数,该函数相当于创建一个子进程,并将函数内的参数传递给该子进程,等同于 阅读全文
posted @ 2014-02-12 18:37 lss1990 阅读(3985) 评论(0) 推荐(0) 编辑
摘要: 在linux下的c++编程中,存在两种链接方式,动态链接和静态链接,假设test1.cpp中的代码如下:#includevoid myFunction(){ printf("this is a test function\n");}int f(){ return 3; }test2.cpp中的代码如下:#includeint g(){ return 4; }app.cpp中的代码如下所示:#includeextern int f();extern int g();int main(){ int res = f(); printf("%d\n",res); 阅读全文
posted @ 2014-02-12 12:45 lss1990 阅读(463) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#includeint main(){ FILE* fp = fopen("test.txt","r"); if(fp == NULL) { fprintf(stderr,"error in open file test.txt,errno %s\n",strerror(errno));//strerror函数显示errno对应的具体错误 exit(-1); } return 0;}读取文件并加入错误显示代码#include#include#include#include#in... 阅读全文
posted @ 2014-02-12 10:43 lss1990 阅读(213) 评论(0) 推荐(0) 编辑