bai_jimmy

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

统计

2017年8月20日 #

1、memcache的守护进程启动方式(2017-8-10)

想开始研究下memcache的源码,不知从哪下手,就从守护进程启动开始吧,主要是比较简单

 

/**
 * 守护进程启动
 * @param nochdir   是否切换到根目录
 * @param noclose   是否关闭标准IO
 * @return 
 */
int deamonize(int nochdir, int noclose) {
    int fd;
    switch (fork()) {   //unistd.h
            //fork出错
        case -1:
            return (-1);
            //子进程
        case 0:
            break;
            //父进程
        default:
            _exit(EXIT_SUCCESS);
    }
    if (setsid() == -1) {
        return (-1);
    }
    if (nochdir == 0) {
        if (chdir("/") != 0) {
            perror("chdir");
            return (-1);
        }
    }
    if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
        if (dup2(fd, STDIN_FILENO) < 0) {
            perror("dup2 stdin");
            return (-1);
        }
        if (dup2(fd, STDOUT_FILENO) < 0) {
            perror("dup2 stdout");
            return (-1);
        }
        if (dup2(fd, STDERR_FILENO) < 0) {
            perror("dup2 stderr");
            return (-1);
        }
    }
    return (0);
}

 

posted @ 2017-08-20 22:38 bai_jimmy 阅读(326) 评论(0) 推荐(0) 编辑

2017年5月15日 #

c++封装简单日志操作

摘要: logger.h 测试文件 阅读全文

posted @ 2017-05-15 14:47 bai_jimmy 阅读(838) 评论(1) 推荐(0) 编辑

2017年4月17日 #

关于vector的内存释放

摘要: http://www.cnblogs.com/biyeymyhjob/archive/2012/09/12/2674004.html 阅读全文

posted @ 2017-04-17 17:00 bai_jimmy 阅读(104) 评论(0) 推荐(0) 编辑

2017年2月5日 #

Linux进程通信-共享内存

摘要: #include #include #include #include #include #include #include #include int fd[2]; int semid; union semun{ int val; struct semid_ds *ds; unsigned short *array; }; ... 阅读全文

posted @ 2017-02-05 13:42 bai_jimmy 阅读(165) 评论(0) 推荐(0) 编辑

2017年2月4日 #

Linux进程通信总结

摘要: 1、信号量 信号量是一种计数器,可以用来控制多个进程对共享资源的访问。他经常作为一种锁机制,防止某个进程正在访问共享资源时,其他进程也进行访问。 因此,信号量主要作为进程间以及同一进程内不同线程的同步手段 1)Api 阅读全文

posted @ 2017-02-04 15:36 bai_jimmy 阅读(154) 评论(0) 推荐(0) 编辑

2017年1月14日 #

php通过消息队列IPC跟C语言进程简单通信

摘要: #include #include #include #include #include /* global variables */ int msg_id = 0; typedef struct{ int type; char mtext[128]; } MSG; void sig_handler(int signo) { ... 阅读全文

posted @ 2017-01-14 01:32 bai_jimmy 阅读(348) 评论(0) 推荐(0) 编辑

2017年1月7日 #

管道的简单应用

摘要: 协同程序 阅读全文

posted @ 2017-01-07 17:49 bai_jimmy 阅读(279) 评论(0) 推荐(0) 编辑

2016年11月3日 #

多文件合并

摘要: #!/bin/bash awk -F "\t" ' function trim(str){ sub(/^[ \t]*/,"",str); sub(/[ \t]*$/,"", str); return str; } NR==FNR{ a[trim($1)] = $0 } ... 阅读全文

posted @ 2016-11-03 19:37 bai_jimmy 阅读(118) 评论(0) 推荐(0) 编辑

2016年10月5日 #

C++ 模版

摘要: 函数模版 类模版 阅读全文

posted @ 2016-10-05 15:07 bai_jimmy 阅读(101) 评论(0) 推荐(0) 编辑

2016年10月3日 #

C++使用vector

摘要: #include #include #include using namespace std; void show(vector v) { for(auto v1 : v){ cout v) { for(vector::const_iterator v1 = v.cbegin(); v1 != v.cend(); v... 阅读全文

posted @ 2016-10-03 22:58 bai_jimmy 阅读(246) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示