随笔分类 - linux环境编程
linux 学习
    
摘要:#include struct timeval tv_begin, tv_end; gettimeofday(&tv_begin, NULL); //此处是要测试的代码 gettimeofday(&tv_end, NULL); 执行时间(微秒) = 1000000 * (tv_end.tv_sec - tv_begin.tv_sec) + tv_end.tv_usec - tv_begi...
        阅读全文
                
摘要:sleep所在头文件 确切说windows下:#include Linux下:#include
        阅读全文
                
摘要:下面使用errno进行错误处理是错误的。 /*调用库函数*/if (errno)	/*处理错误*/原因:上面代码的意图是,调用库函数失败,则会设置非零errno,从而进行错误处理;调用成功,则不进行错误处理。问题是,即使调用成功,也没有强制要求将errno设置为0,即虽然调用库函数成功,但是errno并不一定为0,可能是在调用库函数之前errno就被设置为非零值了。下面代码仍然是错误的。errno = 0;/*调用库函数*/if (errno)	/*处理错误*/原因:这段代码在调用库函数之前将errno设置为0,表面上看,如果调用库函数成功,则不会处理错误。问题在于,即使调用库函数成功,err
        阅读全文
                
摘要:http://bbs.chinaunix.net/thread-3558646-1-1.html 1. 第一步: 确定工具所在的"包" #route –version net-tools 1.6 2. 第二步,到源码下载的网站上搜net-tools 1.6, http://linux.softpedia.com/ 或 www.sourceforge.net
        阅读全文
                
摘要:Bell实验室、通用电气和MIT合作MULTICS(MULTiplexed Infomation and Computing Service,多路复用信息与计算服务),后Bell实验室退出。 Bell实验室只留下Ken Thompson继续研究MULTICS,后他发明精简版MULTICS,即是后来的UNIX。 Thompson和Ritchie(里奇,c语言之父)合作,用c重写UNIX,发表UN...
        阅读全文
                
摘要:http://blog.markloiseau.com/2012/02/get-network-interfaces-in-c/http://www.doctort.org/adam/nerd-notes/enumerating-network-interfaces-on-linux.htmlhttp://www.geekpage.jp/en/programming/linux-network/...
        阅读全文
                
摘要:在调试程序时出现端错误,gdb提示“Program received signal SIGSEGV, Segmentation fault” SIGSEGV 该信号指示进程进行了一次无效内存引用。 SEGV表示段违例(segmentation violation)。
        阅读全文
                
摘要:#include <stdio.h>#include <pthread.h>void *pthread_fun(void *arg){	while (1) { sleep(1); printf("pthread running\n");	}	return((void *)0);}int main(){	pthread_t tid;	pthread_create(&tid, NULL, p...
        阅读全文
                
摘要:终端执行一个进程,该进程创建一个子进程,当Ctrl+c后,父子进程都退出,因为,父子进程捕捉到退出信号的默认动作就是结束进程。 如果,在子进程中捕捉退出信号,动作改为忽略,则ctrl+c后,父进程退出,子进程不会退出,子进程被进程ID为1的init进程领养。 代码如下: #include <stdio.h>#include <signal.h>int main(){	if (fork() ==...
        阅读全文
                
摘要:http://www.cnblogs.com/chio/archive/2007/11/24/970632.html volatile char a; a=0; while(!a){ //do some things; } do_other(); 如果没有 volatile, do_other()不会被执行。 volatile极易改变的意思。 表示用volatile定义的变量会在程序外被改变,每次都必须从内存中读取,而不能把他放在cache或寄存器中重复使用。 在中断程序中经常会用到。
        阅读全文
                
摘要:头文件:#include <sys/time.h>#include <sys/resource.h>原型:int getpriority(int which, int who);int setpriority(int which, int who, int prio);参数:which为PRIO_PROCESS,则who指定进程ID;which为PRIO_PGRP,则who指定进程组ID;which为PRIO_USER,则who指定用户ID.who为0,代表调用该函数的当前进程ID,进程组ID或用户ID.prio -20---19,一般默认为0,pri越小,优先级越高,
        阅读全文
                
摘要:《Unix环境高级编程》初始化一个守护进程的调用,cmd可为守护进程名。void daemonize(const char *cmd){	int i, fd0, fd1, fd2;	pid_t pid;	struct rlimit r1;	struct sigaction sa; /* 设置文件模式创建屏蔽字为0,因为继承得来的文件模式创建屏蔽字可能会拒绝设置某些权限。 */	umask(0); /* 获取最大文件描述符。 */	if (getrlimit(RLIMIT_NOFILE, &r1) < 0) { err_sys("%s...
        阅读全文
                
摘要:1、用户按某些终端键时,引发终端产生的信号。如在终端按Ctrl+c将产生中断信号SIGINT. 2、硬件产生信号,如除数为0,无效的内存引用等。这些条件通常由硬件检测到传给内核,然后内核通知进程。 3、进程调用kill函数可将信号发送给另一个进程或进程组。 4、用户可用kill命令将信号发送给其他进程。 5、当检测到某种软件条件发生时,也可能产生信号。如在网络连接上传来带外数据时产生SIGURG.
        阅读全文
                
摘要:参考http://hi.baidu.com/qiaoyongfeng/item/1c08243807f95949023edc52wait头文件:#include <sys/types.h>#include <sys/wait.h>原型:pid_t wait(int *status);参数:status用来保存被收集进程退出时的一些状态,如果我们队这个子进程是如何死掉的毫不在意,只是想把这个僵尸进程消灭掉,则可设定status为NULL.返回值:如果成功,wait会返回被收集的子进程的进程ID,如果调用进程没有子进程,调用就会失败,此时wait返回-1,同时errno被置
        阅读全文
                
摘要:/* ============================================================================ Name : AlarmSignal.c Author : Version : Copyright : Your copyright notice Description : 每3秒执行一个相同的动作。 ============================================================================ */#include <stdio.h>#i...
        阅读全文
                
摘要:父子进程是共享文件表(文件状态标志、当前文件偏移量和v节点指针)的,和相互独立进程不一样。详细见Unix高级环境编程p175.#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <unistd.h>#include <fcntl.h>#include <string.h>int main(void){ int fd = open("test.txt", O_RDWR | O_CREAT | O_TRUNC); char 
        阅读全文
                
摘要:sudo ip route flush table main
        阅读全文
                
摘要:the pid files contains the process id (a number) of a given program. For example, Apache HTTPD may write it's main process number to a pid file - which is a regular text file, nothing more than that -, and later use the information there contained to stop itself. You can also use that informatio
        阅读全文
                
摘要:设置或获取套接字选项的函数:getsocketopt setsockopt fcntl ioctl头文件:#include <sys/socket.h>原型:int getsocketopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);int setsocketopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);参数:optval和socklen_t在getsocketopt中是值—结果
        阅读全文
                
摘要:在vtun配置的mangle链中有一条规则 -A AS0_MANGLE_TUN -j MARK --set-xmark 0x2000000/0xffffffff 下面分析mark何意。 mark值有何意义 mark字段的值是一个无符号的整数,在32位系统上最大可以是4294967296(就是2的32次方),这足够用的了。比如,我们对一个流或从某台机子发出的所有的包设置了mark值,就可以利用高级...
        阅读全文
                
 
                    
                
 浙公网安备 33010602011771号
浙公网安备 33010602011771号