lighttpd源码学习
2015-08-28 17:10
531 查看
// 固定产生 10 个worker进程工作, 有worker退出时, 重新创建worker。 // 类似于lighttpd 的 watcher,worker模型 // 参考:http://bbs.chinaunix.net/thread-1251434-1-1.html #include <stdio.h> #include <sys/types.h> #include <stdlib.h> #include <unistd.h> void child_main() { printf("child [%5d] is working.\n", getpid()); sleep(5); printf("child [%5d] is done.\n", getpid()); exit(1); } int main() { unsigned int worker_num = 10; int status; pid_t pid; while(1) { if (worker_num > 0) { pid = fork(); if(pid < 0) { perror("fork"); exit(1); }else if( pid == 0 ) { // child child_main(); }else if( pid > 0 ) { // father worker_num--; } }else{ // wait for a child to exit, and update worker_num pid = wait(&status); printf("father: chile [%5d] is done. Create a new one...\n", pid); worker_num++; } } return 0; }
相关文章推荐
- 《TCP/IP详解卷1:协议》——第1章:概述(转载)
- 清除网络共享文件夹密码缓存
- muduo网络库源码学习————Timestamp.cc
- http://www.freebuf.com/
- Response.End(); 用HttpContext.Current.ApplicationInstance.CompleteRequest 代替
- Linux网络编程--IO函数以及示例
- XMLHttpReques对象初认识
- Http Post与Get等
- tomcat配置https
- android网络游戏开发——客户端开发——游戏引擎的选择
- hdu 4731 2013成都赛区网络赛 找规律
- 网络技术新名词笔记(by quqi99)
- 关于修复“启用了不安全的 HTTP 方法”
- Http请求过程
- iOS开发网络篇—数据缓存
- tcp二进制反码求和
- fd_set具体是怎样实现的 http://blog.chinaunix.net/uid-20680966-id-1896524.html
- Note For Linux By Jes(15)-系统配置工具(网络与打印机)与硬件侦测
- iOS监听 网络信号变化
- HTTP 错误 500.19- Internal Server Error 错误解决方法