随笔分类 - Linux/Unix系统编程
学习APUE、Linux/Unix系统编程手册时候的点滴记录
摘要:#include <string.h> #include <errno.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #define MAXLINE 1024 i
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <arpa/inet.h> #define MAXBUF 1024 int main(int argc, char **arg
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <string.h> c
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <string.h> #
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <string.h> c
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <time.h> #include <errno.h> #include <string.h> const
阅读全文
摘要:#include <unistd.h> #include <stdio.h> #include <stdlib.h> const int BUFFSIZE=4096; int main(int argc, char *argv[]) { int n; char buf[BUFFSIZE]; whil
阅读全文
摘要:文件映射:文件映射将一个文件的一部分直接映射到调用进程的虚拟内存中。 一旦一个文件被映射之后就可以通过在相应的内存区域操作字节来访问文件内容了。 #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <stri
阅读全文
摘要:UNIX系统内部对时间的表示方式均是自Epoch以来的秒数来度量的,Epoch亦即通用协调时间的1970年1月1日早晨零点。 这是UNIX系统问世的大致日期,日历时间存储于类型为time_t的变量中。 系统调用gettimeofday(),可于tv指向的缓存区中返回日历时间。 #include <s
阅读全文
摘要:/proc虚拟文件系统,因为其包含的文件和子目录并未存储于磁盘上,而是由内核在进程访问此类信息时动态创建而成。 /proc 各种系统信息 /proc/net 有关网络和套接字的状态信息 /proc/sys/fs 文件系统相关设置 /proc/sys/kernel 各种常规的内核设置 /proc/sy
阅读全文
摘要:#include <unistd.h> #include <signal.h> #include <string.h> #include <sys/wait.h> #include <stdio.h> #define MAXLINE 100 static void sig_int(int); int
阅读全文
摘要:一个简单的ls命令的实现: #include <stdio.h> #include <stdlib.h> #include <dirent.h> int main(int argc, char *argv[]) { DIR *dp; struct dirent *dirp; if(argc != 2
阅读全文
摘要:服务器程序 #include <stdio.h> #include <sys/un.h> #include <sys/socket.h> #include <errno.h> #include <unistd.h> #define SV_SOCK_PATH "/tmp/us_xfr" #define
阅读全文
摘要:线程的主要优势在于,能够通过全局变量来共享信息。必须确保多个线程不会同时修改同一变量,或者某一线程不会读取正由 其他线程修改的变量。临界区是指访问某一共享资源的代码片段,并且这段代码的执行应为原子操作,亦即,同时访问同一共享 资源的其他线程不应中断该片段的执行。可以使用互斥量来保证对任意共享资源的原
阅读全文
摘要:#include <stdio.h> #include <sys/resource.h> int main() { struct rlimit rlim; if(getrlimit(RLIMIT_MEMLOCK, &rlim) == -1) { fprintf(stderr, "getrlimit
阅读全文
摘要:#include <stdio.h> #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> #include <unistd.h> int main(int argc, char *arg
阅读全文
摘要:#include <stdio.h> #include <sys/wait.h> #include <unistd.h> #include <string.h> #define BUF_SIZE 10 int main(int argc, char *argv[]) { int pfd[2]; ch
阅读全文
摘要:#include <stdio.h> #include <stdlib.h> static void atexitFunc1(void) { printf("atexit function 1 called.\n"); } static void atexitFunc2(void) { printf
阅读全文
摘要:#include <stdio.h> #include <unistd.h> static int idata = 111; int main() { int istack = 222; pid_t childPid; switch(childPid = fork()) { case -1: fpr
阅读全文
摘要:uname()系统调用返回了一系列关于主机系统的标识信息。 #include <sys/utsname.h> int uname(struct utsname *utsbuf); Returns 0 on success, or -1 on error #define _UTSNAME_LENGTH
阅读全文