C_Linux
文章平均质量分 70
amaowolf
这个作者很懒,什么都没留下…
展开
-
Zero Copy I: User-Mode Perspective
http://www.linuxjournal.com/article/6345?page=0,2Explaining what is zero-copy functionality for Linux, why it's useful and where it needs work.By now almost everyone has heard of so-ca原创 2012-04-01 12:54:01 · 573 阅读 · 0 评论 -
(5) hashtable <key, data> : hcreate hdestroy hsearch
The three functions hcreate(), hsearch(), and hdestroy() allow the user to create a hash table (only one at a time) which associates a key with any data.#include #include #include /* *原创 2012-10-28 22:07:11 · 917 阅读 · 0 评论 -
C语言字符串处理的库函数
使用C语言字符串处理的库函数,务必包含头文件string.h,即#include 1、 比较字符串大小函数 1) 忽略大小写---strcasecmp函数原型: int strcasecmp (const char *s1, const char *s2);函数说明: 用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异转载 2012-10-22 08:05:09 · 662 阅读 · 0 评论 -
static和extern修饰连接属性
1. static修饰全局变量或函数,表示其只能在所在文件中使用extern修饰变量,表示其来自于其他文件---------------------------------------[root@localhost cpp]# cat source.c#includestatic int height = 8848; // can only be used原创 2012-10-31 08:03:47 · 511 阅读 · 0 评论 -
C库文件说明
ALLOC.H 说明内存管理函数(分配、释放等)。ASSERT.H 定义 assert调试宏。BIOS.H 说明调用IBM—PC ROM BIOS子程序的各个函数。CONIO.H 说明调用DOS控制台I/O子程序的各个函数。CTYPE.H 包含有关字符分类及转换的名类信息(如 isalpha和toascii等)。DIR.H原创 2012-10-31 08:05:22 · 703 阅读 · 0 评论 -
static的作用
在C语言中,static的作用可以归纳为三条。(1):隐藏。当编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性。一个是a.c,另一个是main.c。下面是a.c的内容char a = 'A' // global variablevoid msg(){printf("Hello\n");}你可能会转载 2012-10-31 08:04:22 · 357 阅读 · 0 评论 -
getopt_long 与 optind
命令行参数有长参数如version, 还有短参数 如 v, 那么用这两个都可以。程序处理的时候,会首先把长参数转换成对应的短参数,如会把version转成v, 再进行 v 对应的操作就可以了。命令行参数的选项,有的需要参数,有的不需要参数,或者有的参数是可选的,那么怎么区分呢?首先,对这些选项,如何组织起来? 是以字符串的形式组织起来了。如我有一个程序,有两个选项,-a, -b,转载 2012-10-31 11:40:37 · 536 阅读 · 0 评论 -
getopt
#include //for printf#include //for exit#include #include void print_help(){ puts("srun [-N nodes] [-n tasks] executable\n\ -N number of nodes\n\ -n number of tasks\n\ -h --help p原创 2012-10-31 11:42:00 · 405 阅读 · 0 评论 -
对字符串常量的修改
K&R C中规定字符串中所有字符和NUL终止符都存储于内存的某个位置。可以修改字符串常量。但ANSI C中则规定如果对一个字符串常量进行修改,其结果是未定义的。因此,如果要修改字符串常量,请把它存储在数组中,这样,字符串将存储在普通内存区中,可修改。#includeint main(){char *pstr = "hire";原创 2012-10-31 08:02:53 · 2789 阅读 · 0 评论 -
(4) tree : tsearch tfind tdelete
1.#include #include #include #include /* * tsearch(), tfind(), and tdelete() also return NULL if rootp was NULL on entry. * * void *tsearch(const void *key, void **rootp, int(*compar)(const原创 2012-10-28 22:09:08 · 1326 阅读 · 0 评论 -
(2) array of sturct/string: lfind lsearch and insert
#include#include#include#include/* * void *lfind(const void *key, const void *base, size_t *nmemb, size_t size, int(*compar)(const void *, const void *)); if found return原创 2012-10-28 22:08:07 · 530 阅读 · 0 评论 -
(1) array of string/struct: qsort bsearch
1. The bsearch() function returns a pointer to a matching member of the array, or NULL if no match is found. If there are multiple elements that match the key, the element returned is unspecified原创 2012-10-28 22:05:44 · 611 阅读 · 0 评论 -
用socket实现简单的文件传输
http://atu82.bokee.com/4667560.html服务器端:#include #include #include #include #include #include #include #include #define SERVPORT 6666#define MAXDATASIZE 1024 /*每次最大数据传输量 */ #转载 2012-04-01 12:23:05 · 1081 阅读 · 0 评论 -
关于AF_INET和PF_INET
AF表示ADDRESS FAMILY地址族PF 表示PROTOCL FAMILY协议族Winsock2.h中#define AF_INET 0#define PF_INET AF_INET所以在windows中AF_INET与PF_INET完全一样而在Unix/Linux系统中,在不同的版本中这两者有微小差别对于BSD,是AF,对于POSIX是P转载 2012-03-30 17:08:33 · 508 阅读 · 0 评论 -
sockaddr与sockaddr_in结构体简介
struct sockaddr {unsigned short sa_family; /* address family, AF_xxx */char sa_data[14]; /* 14 bytes of protocol address */};sa_family是地址家族,一般都是“AF_xxx”的形式。好像通常大多用的是都是AF转载 2012-03-30 19:28:24 · 445 阅读 · 0 评论 -
通过Socket通过Client向Server使用sendfile传文件
1. server.c (a)为了将传过来的文件保存为不同的文件内容,故用本机时间的十六进制作为文件名#include#include#include#include#include#include#include#include#include#include#include#include#define oops(msg) { perror(msg)原创 2012-04-01 19:02:58 · 3521 阅读 · 1 评论 -
Linux "零拷贝" sendfile函数中文说明及实际操作分析
Sendfile函数说明 #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);sendfile()是作用于数据拷贝在两个文件描述符之间的操作函数.这个拷贝操作是内核中操作的,所以称为"零拷贝".sendfile函数比起read和write函数高效得多,因为read和write是要转载 2012-04-01 13:00:05 · 932 阅读 · 0 评论 -
sendfile 和epool
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);linux下支持sendfile,这样发送文件,可以直接通过内核调用,减少了到应用程序读写两道操作程序,并降低了内存的使用。看man文档,sendfile在2.6.9以后,infd只能是普通文件,outfd必须是socket。经过试验,在linux9转载 2012-04-01 12:19:19 · 4819 阅读 · 1 评论 -
sizeof vs. strlen enum
#include #include #include enum node_states { NODE_STATE_UNKNOWN, /* node's initial state, unknown */ NODE_STATE_DOWN, /* node in non-usable state */ NODE_STATE_IDLE, /* node idle and available原创 2012-09-24 16:25:24 · 394 阅读 · 0 评论 -
getopt_long
#include //for printf#include //for exit#include #include void print_help(){ puts("srun [-N nodes] [-n tasks] executable\n\ -N number of nodes\n\ -n number of ta原创 2012-10-31 13:40:33 · 413 阅读 · 0 评论 -
(3) double-linked list: insque remque
1. /** * The insque and remque subroutines manipulate queues built from double-linked lists. * Each element in the queue must be in the form of a qelem structure. The next and * prev elements o原创 2012-10-30 14:31:35 · 801 阅读 · 0 评论 -
归并排序
归并排序,不单单是归并排序,应该更重要的是一种分治的思想。把问题大而化小,再将小问题的结果汇总,得到大问题的解。递归的写法更能体现归并的分治思想,但是递归调用,当层次非常多的时候,会影响性能,现在考虑如何把归并的递归方式变成非递归方式。归并的完整描述是:假设初始序列含有n个记录,则可看成是n个有序的子序列,每个子序列的长度为1, 然后两两归并,得到[n/2]个升序为2(或1转载 2012-10-31 16:02:54 · 363 阅读 · 0 评论 -
c语言之宏预处理命令
以#开头,可以放在程序的任何地方#中主要任务1》文件包含:#include#include "file.h"2>宏定义#define name body必须在一行中,否则会出现错误,可以使用延续符\,注意延续符与新行之间不能有空行,否则会导致错误a》常量定义:#define NO 9其中宏体可以使任意类型b》模拟函数:1》无参#define FLUS转载 2012-11-14 17:40:59 · 804 阅读 · 0 评论 -
字符串1
#include #include #include #define OPTIONAL 1#define MANDATORY 2char* allocate_node(size_t nodes_required, char* node_list, int flag, size_t timeout){ char *cmd[256], *flag_str[10]; if(fla原创 2012-11-14 15:08:30 · 432 阅读 · 0 评论 -
自我学会利用Linux系统上已有的开发库
http://zhoulifa.bokee.com/6094520.html1、查看库文件是由哪个软件包提供的空闲时打开/usr/lib目录(因为我知道这个目录下放着一些库文件,是我们开发者可以利用的)想看看我的系统中有哪些库。看到一个libz.so,于是用命令查看:dpkg -S /usr/lib/libz.so此命令输出如下信息:转载 2012-11-15 14:30:58 · 1668 阅读 · 0 评论 -
RPC远程调用编程 (1)
在查看libc6-dev软件包提供的工具(用 dpkg -L libc6-dev 命令)的时候,发现此软件包提供了一个有用的工具rpcgen命令。通过rpcgen的man手册看到此工具的作用是把RPC源程序编译成C语言源程序,从而轻松实现远程过程调用。下面的例子程序的作用是客户端程序取中心服务器上时间的,编程过程如下:先编写一个 “ RPC 语言 ” ( RPC Language (转载 2012-11-15 15:03:45 · 1219 阅读 · 0 评论 -
how to c libraries
C LibrariesIn general, libraries are created from many library source files, and are either built as archive files (libmine.a) that are statically linked into executables that use them, or as shared转载 2012-11-15 15:20:49 · 860 阅读 · 0 评论 -
strcat
strcatFrom Wikipedia, the free encyclopediaJump to: navigation, searchIn computing, the C programming language offers a library function called strcat that allows one memory block to b转载 2012-12-01 19:47:38 · 675 阅读 · 0 评论 -
libevent (1) 入门教程:Echo Server based on libevent
http://felix021.com/blog/read.php?2068花了两天的时间在libevent上,想总结下,就以写简单tutorial的方式吧,貌似没有一篇简单的说明,让人马上就能上手用的。首先给出官方文档吧: http://libevent.org ,首页有个Programming with Libevent,里面是一节一节的介绍libevent,但是感觉信息量转载 2012-11-19 14:10:38 · 2228 阅读 · 0 评论 -
libevent(2) : 用libevent改写server端 实现echo_server
(1) echo_server.clisten_event的callback函数是 do_accept_cbbev (buffer event)的三个callback函数:read_cb, write_cb, error_cb。 本例中,server端无需write_cb函数#include #include #include #include #include #i原创 2012-11-19 16:57:13 · 5714 阅读 · 0 评论 -
C语言预处理命令之条件编译(#ifdef,#else,#error,#endif,#if...)
预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器。可见预处理过程先于编译器对源代码进行处理。在C语言中,并没有任何内在的机制来完成如下一些功能:在编译时包含其他源文件、定义宏、根据条件决定编译时是否包含某些代码。要完成这些工作,就需要使用预处理程序。尽管在目前绝大多数编译器都包含了预处理程序,但通常认为它们是独立于编译器的。预处理过程读入源代码,检查包含预处理指令的语句和宏转载 2012-11-14 17:06:28 · 3195 阅读 · 0 评论 -
Linux编程库简介
Linux编程库简介所谓Linux编程库就是指始终可以被多个Linux软件项目重复使用的代码集。以C语言为例,它包含了几百个可以重复使用的例程和调试程序的工具代码,其中包括函数。如果每次编写新程序都要重新写这些代码会非常不方便,使用编程库有两个主要优点:可以简化编程,实现代码重复使用,进而减小应用程序的大小;可以直接使用比较稳定的代码。Linux下的转载 2012-11-08 20:06:12 · 1065 阅读 · 0 评论 -
str to int, long, float; 数字 转 字符串; 大小写转换等
#include#include#include#includeint main(){ char *str = "-1111.11";/** * double atof(const char *nptr); * int atoi(const char *nptr); * long atol(const char *nptr); * long long atoll(const c原创 2012-11-06 17:28:19 · 4870 阅读 · 0 评论 -
Libc学习
搜索和排序线性表搜索:lfind、lsearch、bsearch哈希搜索:hcreate、hdestroy、hsearch;hcreate_r、hdestroy_r、hsearch_r二叉树搜索:tsearch、tfind、tdelete、tdestroy、twalk模式匹配文件名匹配:fnmatchGlobbing: glob、glob64、wordexp、wor转载 2012-10-23 11:16:29 · 813 阅读 · 0 评论 -
Linux / Unix IO
IO分类标准IO: fopen, fread, fwrite, fseek, fclose, ...系统IO: open, read, write, readv, writev, pread, pwrite, close, fstat, fcntl, select,...异步IO: aio_read, aio_write, lio_listio, aio_error, aio_return转载 2012-10-23 11:29:00 · 436 阅读 · 0 评论 -
JNI 初探 (on RHEL)
1. HelloWorld.java => HelloWorld.classclass HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static {原创 2012-11-01 18:00:44 · 471 阅读 · 0 评论 -
OOB (1)
OOB(out-of-band data)(综合编辑)传输层协议使用带外数据(out-of-band,OOB)来发送一些重要的数据,如过通信一放有重要的数据需要通知对方时,协议能够将这些数据快速地发送到对方.为了发送这些数据,协议一般不使用与普通数据相同的通道,而是使用另外的通道.linux系统的套接字机制支持低层协议发送和接受带外数据.但是TCP协议没有真正意义上的带外数据.为了发送重要协议转载 2012-11-02 16:25:03 · 1935 阅读 · 0 评论 -
OOB (2)
Out Of Band (OOB) 带外数据有个不错的英文站介绍了这个OOB,http://alas.matf.bg.ac.rs/manuals/lspe/snode=125.html 带外数据,也叫紧急数据,跟普通数据没有太大区别,就是在接收时,会单独存放在一个独立缓冲中;读取时可以先被读取到(读取方式与普通数据稍有差别)。每次紧急数据只能发送一个字符。转载 2012-11-02 16:26:53 · 1932 阅读 · 0 评论 -
Linux下.ko, .o, .so, .a, .la文件
.o file - the unlinked output of the compiler - an object file.a - out of using ar to "pack" several .o files into an object archive file. It is an efficient way of keeping track of and being ab转载 2012-11-04 16:50:08 · 5472 阅读 · 0 评论 -
sizeof(city_array) = 8, sizeof(char *) = 8
#include#include#include/** * sizeof(city_array) = 8, sizeof(char *) = 8 * count = sizeof(city_array) / sizeof(char *) = 1 */void print_city_array(int num, char **city_array){ printf("sizeof(c原创 2012-10-28 22:03:08 · 1124 阅读 · 0 评论