摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>int main (int argc, char *argv[]){ int cnt; char buf[100]; cnt = printf("Hello world!\n"); printf("printf ret: %d\n", cnt); printf("strlen: %d\n", strlen("Hello world!\n")); memset(buf, 阅读全文
posted @ 2013-05-07 22:35 robotke1 阅读(949) 评论(0) 推荐(0)
摘要: 例子1:#include <stdio.h>#include <stdlib.h>#include <string.h>int main (int argc, char *argv[]){ /* -------------------------------------- */ char buf[30] = {0}; sprintf(buf, "%8X" , 123); printf("%s\n", buf); memset(buf, 0, sizeof(buf)); sprintf(buf, "%8X&qu 阅读全文
posted @ 2013-05-07 22:17 robotke1 阅读(660) 评论(0) 推荐(0)
摘要: (转载)http://www.cnitblog.com/zouzheng/archive/2008/02/26/40164.html内核同步措施 为了避免并发,防止竞争。内核提供了一组同步方法来提供对共享数据的保护。 我们的重点不是介绍这些方法的详细用法,而是强调为什么使用这些方法和它们之间的差别。 Linux 使用的同步机制可以说从2.0到2.6以来不断发展完善。从最初的原子操作,到后来的信号量,从大内核锁到今天的自旋锁。这些同步机制的发展伴随 Linux从单处理器到对称多处理器的过度;伴随着从非抢占内核到抢占内核的过度。锁机制越来越有效,也越来越复杂。 目前来说内核中原子操作多用来做计数使 阅读全文
posted @ 2013-05-07 21:27 robotke1 阅读(159) 评论(0) 推荐(0)
摘要: fork和vfork都会创建子进程,它们有什么区别呢?一、fork:子进程拷贝父进程的数据段 vfork:子进程与父进程共享数据段二、fork:父、子进程的执行次序不确定 vfork:子进程先运行,父进程后运行#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>int main (int argc, char *argv[]){ int number = 0; pid_t pid; pid = vfork(); number++; printf(&q 阅读全文
posted @ 2013-05-07 20:04 robotke1 阅读(269) 评论(0) 推荐(0)
摘要: (1)用wait和waitpid函数清理僵尸进程,父进程可以阻塞等待子进程结束(2)父进程在信号处理函数中wait()清理子进程其实,子进程在终止时会给父进程发SIGCHLD信号,该信号的默认处理动作是忽略,父进程可以自定义SIGCHLD信号的处理函数,这样父进程只需专心处理自己的工作,不必关心子进程了,子进程终止时会通知父进程,父进程在信号处理函数中调用wait清理子进程即可。例子1:#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>void s 阅读全文
posted @ 2013-05-07 17:40 robotke1 阅读(393) 评论(0) 推荐(0)
摘要: (转载)http://blog.chinaunix.net/uid-21206300-id-3018578.html(1)产生僵尸进程#include <stdio.h>#include <stdlib.h>#include <unistd.h>int main (int argc, char *argv[]){ pid_t pid = fork(); if (pid == 0) { int i = 0; while (i++ < 6) { printf("child running...\n"); sleep(... 阅读全文
posted @ 2013-05-07 16:45 robotke1 阅读(581) 评论(1) 推荐(0)
摘要: (转载)http://www.cnblogs.com/cornsea/archive/2010/06/08/1754369.html例子1:#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <signal.h>#include <sys/prctl.h>void my_system(void){ pid_t pid; pid = fork(); if (pid == 0) { //prctl(PR_SET_PDEATHSIG, SIGHUP); while 阅读全文
posted @ 2013-05-07 15:56 robotke1 阅读(2759) 评论(0) 推荐(0)
摘要: (转载)http://blog.csdn.net/caianye/article/details/6526150linux下: ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程。常用于终止正在运行的程序。 ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程。 ctrl-d 不是发送信号,而是表示一个特殊的二进制值,表示 EOF。 ctrl-/ 发送 SIGQUIT 信号给前台进程组中的所有进程,终止前台进程并生成 core 文件。Key Function Ctrl-c Kill foreground process Ctrl-z Suspend 阅读全文
posted @ 2013-05-07 13:32 robotke1 阅读(248) 评论(0) 推荐(0)
摘要: (转载)http://www.cnblogs.com/duzouzhe/archive/2009/06/19/1506699.html(一)Linux网络编程--网络知识介绍Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户端 在网络程序中,如果一个程序主动和外面的程序通信,那么我们把这个程序称为客户端程序。 比如我们使用ftp程序从另外一 个地方获取文件的时候,是我们的ftp程序主动同外面进行通信(获取文件), 所以这个地方我们的ftp程序就是客户端程序。 服务端 和客户端相对应的程序即为服务端程序. 阅读全文
posted @ 2013-05-07 13:31 robotke1 阅读(408) 评论(0) 推荐(0)
摘要: (转载)http://www.cnblogs.com/zeroone/archive/2010/05/05/1727659.htmlDAYOFWEEK(date) 返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)mysql> select DAYOFWEEK('1998-02-03'); -> 3 DAYOFMONTH(date) 返回date是一月中的第几日(在1到31范围内) mysql> select DAYOFMONTH('1998-02-03'); -> 3 DAYOFYEAR(date) 返回d 阅读全文
posted @ 2013-05-07 13:30 robotke1 阅读(155) 评论(0) 推荐(0)