摘要: #include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <dirent.h>#include <fcntl.h>int main(int argc, char **argv){ struct dirent *dirp; DIR *fdir; fdir = opendir("/proc"); while(dirp = readdir(fdir)){ if(strcmp(dirp->d 阅读全文
posted @ 2012-08-26 15:21 庄庄庄 阅读(443) 评论(3) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#define dprint(A) printf("%s:\t\t%p\n", #A, A);void foo(int n, int m){ int xy = 8; int a[n]; int x = 1; float y = 1.0; dprint(&xy); dprint(&x); dprint(&y); printf("&a[%d]:\t%p\n",m, &a[m]); dprint(a);}int main(i 阅读全文
posted @ 2012-08-25 21:37 庄庄庄 阅读(828) 评论(0) 推荐(0) 编辑
摘要: 来源:http://bbs.chinaunix.net/thread-2011594-1-1.html前面已经谈了内核加载与系统引导过程,下面我们来看看内核的 do_fork() 函数是如何创建一个新的进程的。在 Linux 内核中,供用户创建进程的系统调用fork()函数的响应函数是 sys_fork()、sys_clone()、sys_vfork()。这三个函数都是通过调用内核函数 do_fork() 来实现的。根据调用时所使用的 clone_flags 参数不同,do_fork() 函数完成的工作也各异。这部分内容简单,我不打算就此而展开分析。下面我们重点来讲解以下 do_fork() 阅读全文
posted @ 2012-08-24 09:49 庄庄庄 阅读(386) 评论(8) 推荐(0) 编辑
摘要: char *gets(char *str);str 的结束符 \0, \n; 无最大长度; 不接收\nchar *fgets(char *str, int maxlen, FILE *fp);str 的结束符\0; 最大长度 maxlen; 接收\n---------------------size_t read(int fd, void *buf, size_t count);从fd中读入count个字符到buf中;write(int fd, const void *buf, size_t count);把buf 中的count个字符写入到fd中;注意 当buf为字符串时,记得要把最后的\0 阅读全文
posted @ 2012-08-21 15:07 庄庄庄 阅读(136) 评论(1) 推荐(0) 编辑
摘要: 竖直方向分屏:vsplit 2.c:vs 2.c切换窗口ctrl ww----------------- 下午#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <unistd.h>#define LEN 1024#define R 0#define W 1void trans(char *s){ char ch; while(ch = *s) *s++ = toupper(ch); *s = 0;}int main(){ int pipe_a2b[2]; int pip 阅读全文
posted @ 2012-08-21 13:50 庄庄庄 阅读(348) 评论(1) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <sys/unistd.h>#include <fcntl.h>#include <sys/wait.h>int main(int argc, char *argv){ pid_t pid = fork(); if(pid < 0){ perror("fork"); exit(0); } if(pid == 0){ // child process int n = 8; while(n--){ printf(" 阅读全文
posted @ 2012-08-21 10:49 庄庄庄 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 1 #include <stdio.h> 2 #include <string.h> 3 4 char *my_strtok(char *buf, char *delims) 5 { 6 static int first = 1; 7 if(first){ // 8 first = 0; // 互斥操作,确保后面代码仅在本次调用执行 9 return strtok(buf, delims);10 } else {11 return strtok(NULL, delims);12 }13 }14 15 int m... 阅读全文
posted @ 2012-08-18 03:38 庄庄庄 阅读(444) 评论(0) 推荐(0) 编辑
摘要: ---------- GETPI.Cdouble getPI(void){ return 3.14159265358979324;}---------- MYLIB.H#ifndef _MYLIB_H_#define _MYLIB_H_void say(const char *str);double getPI(void);#endif //_MYLIB_H_---------- RUN.BAT@prompt me#$srem 生成静态库 mylib.agcc -o say.o -c say.cgcc -o getPI.o -c getPI.car rs mylib.a say.o ge... 阅读全文
posted @ 2012-08-17 01:27 庄庄庄 阅读(621) 评论(0) 推荐(0) 编辑
摘要: # 英-中文对照 格式化的perl代码open(fd, ">result.txt");while (<DATA>) { if ($_ =~ /./) { ($english, $chinese) = /(.*?)([\x80-\xff].*)/; $english =~ s/(.*?)(\s+$)/\1/; print fd sprintf ("%-40s%s\n", $english, $chinese); }}__DATA__abstract 抽象的.... 1 abstract ... 阅读全文
posted @ 2012-08-11 00:24 庄庄庄 阅读(3405) 评论(0) 推荐(1) 编辑
摘要: 原来我一直都读错了,今天才知道发音为 模(mú)板,普通话真差。。 阅读全文
posted @ 2012-08-09 22:08 庄庄庄 阅读(238) 评论(0) 推荐(0) 编辑