`
luckyclouds
  • 浏览: 109076 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

lighttpd中的watcher workers模型

    博客分类:
  • c
阅读更多
/* start watcher and workers */
	num_childs = srv->srvconf.max_worker;
	if (num_childs > 0) {
		int child = 0;
		while (!child && !srv_shutdown && !graceful_shutdown) {
			if (num_childs > 0) {
				switch (fork()) {
				case -1:/*出错返回父进-1*/
					return -1;
				case 0:/*fork成功 返回给子进程 0*/
					child = 1;
					break;
				default::/*fork成功 返回给父进程的是子进程ID*/
					num_childs--;
					break;
				}
			} else {
				int status;

				if (-1 != wait(&status)) {
					/** 
					 * one of our workers went away 
					 */
					num_childs++;
				} else {
					switch (errno) {
					case EINTR:
						/**
						 * if we receive a SIGHUP we have to close our logs ourself as we don't 
						 * have the mainloop who can help us here
						 */
						if (handle_sig_hup) {
							handle_sig_hup = 0;

							log_error_cycle(srv);

							/**
							 * forward to all procs in the process-group
							 * 
							 * we also send it ourself
							 */
							if (!forwarded_sig_hup) {
								forwarded_sig_hup = 1;
								kill(0, SIGHUP);
							}
						}
						break;
					default:
						break;
					}
				}
			}
		}

		/**
		 * for the parent this is the exit-point 
		 */
		if (!child) {
			/** 
			 * kill all children too 
			 */
			if (graceful_shutdown) {
				kill(0, SIGINT);
			} else if (srv_shutdown) {
				kill(0, SIGTERM);
			}

			log_error_close(srv);
			network_close(srv);
			connections_free(srv);
			plugins_free(srv);
			server_free(srv);
			return 0;
		}
	}

这个模型主要是利用了fork函数的特性,fork函数 成功的时候,在子进程中获得返回值0,在父进程中获得为子进程的ID,失败出错时 是在父进程中获得-1
分享到:
评论

相关推荐

    Lighttpd源码分析_mobi

    主要内容包括:lighttpd介绍与分析准备工作、lighttpd网络服务主模型、lighttpd数据结构、伸展树、日志系统、文件状态缓存器、配置信息加载、i/o多路复用技术模型、插件链、网络请求服务响应流程、请求响应数据快速...

    最新lighttpd源码 lighttpd-1.4.22

    lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多...

    lighttpd代码阅读资料

    lighttpd代码阅读资料 参数的 web服务器

    Lighttpd源码分析

    Lighttpd源码分析就是一本介绍分析Lighttpd源码的初级读本,其主要目标在于:一方面让已经接触过网络编程的读者可以从Lighttpd这个开源项目中学习到更深入实际的网络编程知识,另一方面也可以让使用Lighttpd作为自己...

    ubuntu lighttpd实现websocket

    1、下载mongoose使用mongoose中的example中的websocket_chat,实现websocket 2、websocket_chat源码下载路径 官网:https://cesanta.com 论坛:https://forum.mongoose-os.com/index.php?p=/categories/mongoose ...

    lighttpd-1.4.20.tar

    lighttpd-1.4.20.tar lighttpd-1.4.20.tar

    lighttpd 主工作模式

    lighttpd 流程分析工作模式,帮助理解lighttpd

    lighttpd fastcgi

    进入cgi-bin目录中编译方式如下 2228 gcc -o caoft.fcgi echo.c -lpthread -lfcgi 2229 gcc -o caoft.fcgi size.c -lpthread -lfcgi 2230 gcc -o caoft.fcgi threaded.c -lpthread -lfcgi 2231 gcc -o caoft....

    varnish+lighttpd配置

    varnish+lighttpd配置

    最新lighttpd-1.4.28源码下载

    最新lighttpd-1.4.28源码下载最新lighttpd-1.4.28源码下载最新lighttpd-1.4.28源码下载最新lighttpd-1.4.28源码下载最新lighttpd-1.4.28源码下载最新lighttpd-1.4.28源码下载

    lighttpd完全学习

    lighttpd完全学习,适合新手文档参考,ppt文件

    lighttpd分析

    lighttpd采用的是多进程+多路复用(如select,epoll)的网络模型,它对多路复用IO操作的封装将作为下一个专题的内容,本次将讲解它所采用的多进程模型.

    lighttpd-1.4.45_lighttpd服务器_

    lighttpd轻量级web嵌入式服务器,方便嵌入式平台移植,小巧安全

    lighttpd-1.4.20-cmake

    lighttpd-1.4.20-cmake

    lighttpd-1.4.26 源码

    lighttpd-1.4.26 源码,官方直接下载,学习的好资源。

    lighttpd配置和启动脚本

    包括lighttpd.conf配置文件以及用于控制web server启动和停止的脚本。

    lighttpd-1.4.55移植配置与测试.rar

    交叉编译最新版的lighttpd-1.4.55,配置与测试CGI与HTML.内含 lighttpd-1.4.55源码,移植教程,cgi测试代码,html测试代码.测试cgi时,浏览器中应该输入192.168.100.30/cgi-bin/xx.cgi .其中 192.168.100.30为开发板的ip

    Lighttpd 的windows版本

    Lighttpd 的windows版本 Lighttpd 1.4.35 发布了,该版本包含很多 bug 修复,包括 scan.coverity.com 扫描的问题。但最主要的是一个 SQL 注入(和路径遍历)问题:

    lighttpd-1.4.20源代码

    lighttpd-1.4.20源代码

    lighttpd源码

    Lighttpd是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI,CGI,Auth,输出压缩(output compress),URL重写,Alias等重要功能;而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多...

Global site tag (gtag.js) - Google Analytics