当前位置: 首页 > news >正文

Unix Network Programming Episode 88

‘inetd’ Daemon

On a typical Unix system, there could be many servers in existence, just waiting for a client request to arrive. Examples are FTP, Telnet, Rlogin, TFTP, and so on. With systems before 4.3BSD, each of these services had a process associated with it. This process was started at boot-time from the file /etc/rc, and each process did nearly identical startup tasks: create a socket, bind the server’s well-known port to the socket, wait for a connection (if TCP) or a datagram (if UDP), and then fork. The child process serviced the client and the parent waited for the next client request. There are two problems with this model:

1.All these daemons contained nearly identical startup code, first with respect to socket creation, and also with respect to becoming a daemon process (similar to our daemon_init function).
2.Each daemon took a slot in the process table, but each daemon was asleep most of the time.

The 4.3BSD release simplified this by providing an Internet superserver: the inetd daemon. This daemon can be used by servers that use either TCP or UDP. It does not handle other protocols, such as Unix domain sockets. This daemon fixes the two problems just mentioned:

1.It simplifies writing daemon processes since most of the startup details are handled by inetd. This obviates the need for each server to call our daemon_init function.
2.It allows a single process (inetd) to be waiting for incoming client requests for multiple services, instead of one process for each service. This reduces the total number of processes in the system.

Specifying the wait flag for a datagram service changes the steps done by the parent process. This flag says that inetd must wait for its child to terminate before selecting on this socket again. The following changes occur:

1.When fork returns in the parent, the parent saves the process ID of the child. This allows the parent to know when this specific child process terminates, by looking at the value returned by waitpid.
2.The parent disables the socket from future selects by using the FD_CLR macro to turn off the bit in its descriptor set. This means that the child process takes over the socket until it terminates.
3.When the child terminates, the parent is notified by a SIGCHLD signal, and the parent’s signal handler obtains the process ID of the terminating child. It reenables select for the corresponding socket by turning on the bit in its descriptor set for this socket.

‘daemon_inetd’ Function

We can call from a server we know is invoked by inetd.

#include "unp.h"
#include <syslog.h>extern int daemon_proc;void daemon_inetd(const char *pname, int facility)
{daemon_proc=1;openlog(pname, LOG_PID, facility);
}

daemon_inetd function: daemonizes process run by inetd

#include "unp.h"
#include <time.h>int main(int argc, char **argv)
{socklen_t len;struct sockaddr *clientaddr;char buff[MAXLINE];time_t ticks;daemon_inetd(argv[0],0);clientaddr=Malloc(sizeof(struct sockaddr_storage));len=sizeof(struct sockaddr_storage);Getpeername(0,clientaddr, &len);err_msg("connection from %s", Sock_ntop(clientaddr, len));ticks=time(NULL);snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));Write(0,buff, strlen(buff));Close(0);return 0;
}

Protocol-independent daytime server that can be invoked by inetd

相关文章:

Unix Network Programming Episode 88

‘inetd’ Daemon On a typical Unix system, there could be many servers in existence, just waiting for a client request to arrive. Examples are FTP, Telnet, Rlogin, TFTP, and so on. With systems before 4.3BSD, each of these services had a process associate…...

Java面试题之11MySQL

你对MySQL执行计划怎么看 执行计划就是SQL的执行查询的顺序&#xff0c;以及如何使用索引查询&#xff0c;返回的结果集的行数 在MySQL中&#xff0c;我们可以通过explain命令来查看执行计划。其语法如下&#xff1a; EXPLAIN SELECT * FROM table_name WHERE conditions;在…...

R语言:多值提取到点

ArcGIS中有相关工具实现多值提取到点的功能&#xff0c;在这里&#xff0c;我将使用R语言进行操作&#xff1a; library(dplyr) library(readxl) library(sf) library(raster)setwd("D:/Datasets") Bio <- stack(paste0("D:/Datasets/Data/worldclim2_1km/…...

八股文打卡day27——数据库(4)

面试题&#xff1a;讲一下事务的隔离级别&#xff1f; 我的回答&#xff1a; 因为事务之间的隔离性&#xff0c;造成了一些问题&#xff0c;比如说&#xff1a;脏读、不可重复读和幻读&#xff08;虚读&#xff09;。 1.什么叫脏读&#xff1f; 就是一个事务读取到了另一个事…...

Java桥接模式源码剖析及使用场景

目录 一、介绍二、项目管理系统中使用桥接模式三、权限管理中使用桥接模式四、Java JDBC中使用桥接模式 一、介绍 它的主要目的是将抽象化与实现化分离&#xff0c;使得二者可以独立变化&#xff0c;就像一个桥&#xff0c;将两个变化维度连接起来。各个维度都可以独立的变化。…...

【异常处理】verilator安装时出现异常 make: *** [Makefile:195: verilator_gantt.1] Error 13

在ubuntu中安装verilator工具时执行make出现该报错。 当我出现这个报错的时候我一脸懵逼&#xff0c;因为网上找不到相关解决办法。 后来想到我的verilator是从github上下载zip&#xff0c;然后解压后传到ubuntu上的&#xff0c;windows上解压我记得会把-替换成_&#xff0c;这…...

测试一下 Anthropic 宣称超过 GPT-4 的 Claude 3 Opus

测试一下 Anthropic 宣称超过 GPT-4 的 Claude 3 Opus 0. 引言1. 测试 Claude 3 Opus3. 试用 api key 限制 0. 引言 今天测试一下 Anthropic 发布的 Claude 3 Opus。 3月4日&#xff0c;Anthropic 宣布推出 Claude 3 型号系列&#xff0c;该系列在广泛的认知任务中树立了新的…...

【题解】—— LeetCode一周小结10

【题解】—— 每日一道题目栏 上接&#xff1a;【题解】—— LeetCode一周小结9 4.用栈实现队列 题目链接&#xff1a;232. 用栈实现队列 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作&#xff08;push、pop、peek、empty&#xff09;&#xff1a…...

Android studio虚拟调试出现“我的APP keeps stopping”问题

问题如图&#xff1a; 遇到这种情况&#xff0c;一看代码&#xff0c;也没有报错呀&#xff0c;怎么不能运行呢&#xff1f;不要慌&#xff01;我们一步一步来。 1、查看Logcat日志 在Android Studio中查看Logcat窗口&#xff0c;可以获取应用程序崩溃时的详细错误信息&…...

【Web】浅聊Java反序列化之Spring2链——两层动态代理

目录 简介 简话JdkDynamicAopProxy 关于target的出身——AdvisedSupport EXP 请确保已阅读过前文或对Spring1链至少有一定认知&#xff1a;【Web】浅聊Java反序列化之Spring1链——三层动态代理-CSDN博客 简介 Spring2 和 Spring1 的反序列化过程基本相同&#xff0c;唯一…...

2386. 找出数组的第 K 大和

2386. 找出数组的第 K 大和 题目链接&#xff1a;2386. 找出数组的第 K 大和 代码如下&#xff1a; //优先队列 //参考&#xff1a;https://leetcode.cn/problems/find-the-k-sum-of-an-array/solutions/2668280/zhao-chu-shu-zu-de-di-k-da-he-by-leetcod-z5kq class Soluti…...

Pytorch学习 day10(L1Loss、MSELoss、交叉熵Loss)

Loss loss的作用如下&#xff1a; 计算实际输出和真实值之间的差距为我们更新模型提供一定的依据&#xff08;反向传播&#xff09; L1Loss 绝对值损失函数&#xff1a;在每一个batch_size内&#xff0c;求每个输入x和标签y的差的绝对值&#xff0c;最后返回他们平均值 M…...

2.2 传统经济学在耍赖

传统经济学中&#xff0c;主体的行为决策是研究的重点对幸福的追求不是传统经济学的研究重点&#xff0c;决策才是。在传统经济学那里&#xff0c;只要能搞清楚是什么决定了决策就可以了。 传统经济学用人们对物品的喜好的排序去替代了对幸福的直接度量。这样做有一个好处&…...

【算法面试题】-04

执行时长 def min_execution_time(n, size, tasks):a 0ans sizei 0while i < size:tmp tasks[i]a tmpif a < n:a 0else:a - ni 1ans a // nif a % n ! 0:ans 1return ans# 读取输入 n int(input()) size int(input()) tasks list(map(int, input().split()))…...

力扣hot100:152.乘积最大子数组(动态规划)

一个子数组问题&#xff0c;我们要使用线性dp&#xff0c;最好先考虑以i结尾&#xff0c;如果定义dp[i]为前i个数最大子数组乘积值 那么dp[i-1]就无法转移到dp[i]。因此我们先考虑dp[i]定义为以第i个数结尾的最大子数组乘积值。 53. 最大子数组和 最大子数组和是一个动态规划问…...

【python 】----Pytest基础知识与进阶知识

定义 用于编写和执行Python测试全功能测试框架(工具),是一个第三方库 安装 pip insatll pytest 安装pytest --version 校验 pytest的组成构成 不写调用语句也可以执行函数内容 在用例运行语句里面: -s:指的是开启与终端的交互,如果没有-s(程序不会输入与打印),一条用…...

谷歌开源的LLM大模型 Gemma 简介

相关链接&#xff1a; Hugging face模型下载地址&#xff1a;https://huggingface.co/google/gemma-7bGithub地址&#xff1a;https://github.com/google/gemma_pytorch论文地址&#xff1a;https://storage.googleapis.com/deepmind-media/gemma/gemma-report.pdf官方博客&…...

深入理解 Vuex:从基础到应用场景

前言 在之前的文章中&#xff0c;我们已经对 Vue.js 有了一定的了解。今天我们要对Vue官方的状态共享管理器Vuex进行详细讲解&#xff0c;将其基本吃透&#xff0c;目标是面对大多数业务需求&#xff1b; 一、介绍 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用…...

自定义 classNames hooks

什么是自定义 hooks 自定义hooks是react提供的编写公共函数的方法 自定hooks 和 通用函数的区别 一定有人会说 hooks 可以使用react 的方法&#xff0c;但是公共函数也可以&#xff0c;因为 jsx 语法的原因 函数必须开头进行大写 其实这些都是 react 的语法规范&#xff…...

玩转centos 下的core 文件

玩转centos 下的core 文件 ------------------------------------------------------------ author: hjjdebug date: 2024年 03月 06日 星期三 12:38:35 CST description: 玩转centos 下的core 文件 ------------------------------------------------------------ 一: 准备一…...

React hook之useRef

React useRef 详解 useRef 是 React 提供的一个 Hook&#xff0c;用于在函数组件中创建可变的引用对象。它在 React 开发中有多种重要用途&#xff0c;下面我将全面详细地介绍它的特性和用法。 基本概念 1. 创建 ref const refContainer useRef(initialValue);initialValu…...

如何在看板中有效管理突发紧急任务

在看板中有效管理突发紧急任务需要&#xff1a;设立专门的紧急任务通道、重新调整任务优先级、保持适度的WIP&#xff08;Work-in-Progress&#xff09;弹性、优化任务处理流程、提高团队应对突发情况的敏捷性。其中&#xff0c;设立专门的紧急任务通道尤为重要&#xff0c;这能…...

如何在最短时间内提升打ctf(web)的水平?

刚刚刷完2遍 bugku 的 web 题&#xff0c;前来答题。 每个人对刷题理解是不同&#xff0c;有的人是看了writeup就等于刷了&#xff0c;有的人是收藏了writeup就等于刷了&#xff0c;有的人是跟着writeup做了一遍就等于刷了&#xff0c;还有的人是独立思考做了一遍就等于刷了。…...

群晖NAS如何在虚拟机创建飞牛NAS

套件中心下载安装Virtual Machine Manager 创建虚拟机 配置虚拟机 飞牛官网下载 https://iso.liveupdate.fnnas.com/x86_64/trim/fnos-0.9.2-863.iso 群晖NAS如何在虚拟机创建飞牛NAS - 个人信息分享...

Python 实现 Web 静态服务器(HTTP 协议)

目录 一、在本地启动 HTTP 服务器1. Windows 下安装 node.js1&#xff09;下载安装包2&#xff09;配置环境变量3&#xff09;安装镜像4&#xff09;node.js 的常用命令 2. 安装 http-server 服务3. 使用 http-server 开启服务1&#xff09;使用 http-server2&#xff09;详解 …...

抽象类和接口(全)

一、抽象类 1.概念&#xff1a;如果⼀个类中没有包含⾜够的信息来描绘⼀个具体的对象&#xff0c;这样的类就是抽象类。 像是没有实际⼯作的⽅法,我们可以把它设计成⼀个抽象⽅法&#xff0c;包含抽象⽅法的类我们称为抽象类。 2.语法 在Java中&#xff0c;⼀个类如果被 abs…...

Vue 模板语句的数据来源

&#x1f9e9; Vue 模板语句的数据来源&#xff1a;全方位解析 Vue 模板&#xff08;<template> 部分&#xff09;中的表达式、指令绑定&#xff08;如 v-bind, v-on&#xff09;和插值&#xff08;{{ }}&#xff09;都在一个特定的作用域内求值。这个作用域由当前 组件…...

ZYNQ学习记录FPGA(一)ZYNQ简介

一、知识准备 1.一些术语,缩写和概念&#xff1a; 1&#xff09;ZYNQ全称&#xff1a;ZYNQ7000 All Pgrammable SoC 2&#xff09;SoC:system on chips(片上系统)&#xff0c;对比集成电路的SoB&#xff08;system on board&#xff09; 3&#xff09;ARM&#xff1a;处理器…...

在 Visual Studio Code 中使用驭码 CodeRider 提升开发效率:以冒泡排序为例

目录 前言1 插件安装与配置1.1 安装驭码 CodeRider1.2 初始配置建议 2 示例代码&#xff1a;冒泡排序3 驭码 CodeRider 功能详解3.1 功能概览3.2 代码解释功能3.3 自动注释生成3.4 逻辑修改功能3.5 单元测试自动生成3.6 代码优化建议 4 驭码的实际应用建议5 常见问题与解决建议…...

DAY 26 函数专题1

函数定义与参数知识点回顾&#xff1a;1. 函数的定义2. 变量作用域&#xff1a;局部变量和全局变量3. 函数的参数类型&#xff1a;位置参数、默认参数、不定参数4. 传递参数的手段&#xff1a;关键词参数5 题目1&#xff1a;计算圆的面积 任务&#xff1a; 编写一…...