
C函数-ABCDEFG
jichunlai
学着生活
展开
-
使用alarm和setjmp实现超时控制
#include #include #include #include #include #include #define JMP_VALUE 12345static jmp_buf test_jmp_env;static void test_alarm(int n){ printf("alarm signal:%d\r\n", n); longjmp(test_原创 2013-04-03 15:02:38 · 1818 阅读 · 0 评论 -
使用expect自动输入ssh密码
不使用密钥对时可以使用expect模拟密码输入动作#!/usr/bin/expect -fspawn ssh -o StrictHostKeyChecking=no serveripexpect "*?assword:*"sleep 1send "password\r"expect "]#"send "/bin/echo something\r"sleep原创 2013-09-06 16:25:18 · 800 阅读 · 0 评论 -
chroot备忘
*root用户才有权限执行chroot原创 2013-07-16 13:19:35 · 437 阅读 · 0 评论 -
堆,栈,函数,alloca
来自网络资料和我的理解,如有错误,敬请指正!alloca() 是什么?为什么不提倡使用它?在调用 alloca() 的函数返回的时候, 它分配的内存会自动释放。也就是说, 用 alloca 分配的内存在某种程度上局部于函数的 ``堆栈帧" 或上下文中。alloca() 不具可移植性, 而且在没有传统堆栈的机器上很难实现。 当它的返回值直接传入另一个函数时会带来问题, 如 fge原创 2013-05-15 17:42:32 · 2119 阅读 · 0 评论 -
使用getrusage获取进程使用系统资源信息
#include #include #include #include #include #include int main(void){ while(1) { struct rusage ru; memset(&ru, 0, sizeof(struct rusage)); getrusage(RUSAGE_SELF,原创 2013-04-03 14:49:54 · 2440 阅读 · 0 评论 -
gettimeofday()函数的使用方法:
一.gettimeofday()函数的使用方法:1.简介:在C语言中可以使用函数gettimeofday()函数来得到时间。它的精度可以达到微妙2.函数原型:#includeint gettimeofday(struct timeval*tv,struct timezone *tz )3.说明:gettimeofday()会把目前的时间用tv 结构体转载 2013-04-28 16:42:27 · 1879 阅读 · 0 评论 -
epoll实例
#include #include #include #include #include #include #include #include #include #include #include #include #define LISTENQ 20#define SERV_PORT 5000typedef struct task_原创 2012-08-31 17:37:28 · 1764 阅读 · 0 评论 -
getopt实例
#include #include int main(int argc, const char **argv){ int c; while (1) { int option_index = 0; struct option long_options[] = { { "type原创 2012-08-31 18:07:04 · 1706 阅读 · 0 评论 -
flock简介
flock() 的函数原型如下所示: int flock(int fd, int operation);其中,参数 fd 表示文件描述符;参数 operation 指定要进行的锁操作,该参数的取值有如下几种: LOCK_SH:表示要创建一个共享锁,在任意时间内,一个文件的共享锁可以被多个进程拥有; LOCK_EX:表示创建一个排他锁,在任意时间内,一个文转载 2012-09-05 15:34:25 · 1911 阅读 · 0 评论 -
C函数ftw()
ftw遍历目录树表头文件:#include 定义函数:int ftw(const char *dir, int (*fn) (const *file, const struct stat *sb, int flag), int depth)函数说明:ftw() 会从参数dir指定的 目录开始,往下一层层地递归式遍历子 目录。ftw()会传三个参数给fn(), 第一个参数*file原创 2012-09-06 07:23:43 · 3332 阅读 · 0 评论 -
C alarm实例
#include #include #include #include #include #define ALARM_SECONDS 1#define SLEEP_SECONDS 1//alarm handlevoid alarm_handle(int sig);static unsigned int index = 0;int main(v原创 2012-09-06 07:24:02 · 1566 阅读 · 0 评论 -
getpwnam
#include #include #include int main(int argc, char* argv[]){ struct passwd *ptPWD = getpwnam("daemon"); if(ptPWD != NULL) { printf("uid=%d,gid=%d\r\n", ptPWD->pw_uid,原创 2013-01-14 10:50:26 · 1380 阅读 · 0 评论 -
使用getrlimit控制进程使用系统CPU
#include #include #include #include #include void sigxcpu_handler(int signum){ printf ("SIGXCPU Received!\n"); //可以在这里就退出进程 exit(1);}void sigkill_handler(int signum){ printf ("SIGKILL r原创 2013-04-03 14:19:02 · 1792 阅读 · 0 评论 -
curl wget gzip
Apache启用gzip/deflate或者Nginx启用gzip之后用wget测试的话需要加上--header="accept-encoding:gzip"用curl则加上--compressed浪费了20分钟在这选项上,milkcurl http://www.favormy.com 2>/dev/nullwget http://www.1mima.com 2>/de转载 2016-04-27 10:59:12 · 2562 阅读 · 0 评论