close与shutdown系统调用
使用多线程时,pthread_create的参数flag有CLONE_FILES, 最终调用do_fork(),并且会根据CLONE_FILES标志来调用copy_files()来共享父进程中的文件描述符(这里包括socketfd)。
使用多进程时,fork的参数flag没有CLONE_FILES, 最终调用do_fork(),子进程会把文件描述符的引用计数加一,即把struct files_struct成员f_count++。
在单进程、单线程、多线程时,close()会调用tcp_close();
在多进程时,只是减少f_count引用计数,在f_count为0时才会调用tcp_close()。
而shutdown()与进程线程类型无关,都是直接调用tcp_shutdown()。
NAME
shutdown - shut down part of a full-duplex connection
SYNOPSIS
#include <sys/socket.h>
int shutdown(int sockfd, int how);
DESCRIPTION
The shutdown() call causes all or part of a full-duplex connection on the socket associated with sockfd
to be shut down. If how is SHUT_RD, further receptions will be disallowed. If how is SHUT_WR, further
transmissions will be disallowed. If how is SHUT_RDWR, further receptions and transmissions will be
disallowed.
NAME
close - close a file descriptor
SYNOPSIS
#include <unistd.h>
int close(int fd);
DESCRIPTION
close() closes a file descriptor, so that it no longer refers to any file and may be reused. Any record
locks (see fcntl(2)) held on the file it was associated with, and owned by the process, are removed
(regardless of the file descriptor that was used to obtain the lock).
If fd is the last file descriptor referring to the underlying open file description (see open(2)), the
resources associated with the open file description are freed; if the descriptor was the last reference
to a file which has been removed using unlink(2) the file is deleted.
close与shutdown系统调用的更多相关文章
- shutdown系统调用
/* * Shutdown a socket. */ SYSCALL_DEFINE2(shutdown, int, fd, int, how) { int err, fput_needed; stru ...
- TCP层shutdown系统调用的实现分析
概述 shutdown系统调用在tcp层会调用两个函数,对于ESTABLISHED状态需要调用tcp_shutdown关闭连接,对于LISTEN和SYN_SENT状态则需要以非阻塞模式调用tcp_di ...
- 关于socket的关闭:close和shutdown
通过两种方式可以关闭一个socket:close和shutdown.直接调用close关闭socket存在以下两个问题: 1. close只是将socket 描述字的访问计数减1,仅当描述字的访问计数 ...
- Socket shutdown close简要分析
shutdown 系统调用关闭连接的读数据通道 写数据通道 或者 读写数据通道: 关闭读通道:丢弃socket fd 读数据以及调用shutdown 后到达的数据: 关闭写通道:不同协议处理不同:t ...
- TCP/IP详解--连接状态变迁图CLOSE_WAIT
终止一个连接要经过4次握手.这由TCP的半关闭(half-close)造成的.既然一个TCP连接是全双工(即数据在两个方向上能同时传递,可理解为两个方向相反的独立通道),因此每个方向必须单独地进行关闭 ...
- Linux 高性能服务器编程——TCP协议详解
问题聚焦: 本节从如下四个方面讨论TCP协议: TCP头部信息:指定通信的源端端口号.目的端端口号.管理TCP连接,控制两个方向的数据流 TCP状态转移过程:TCP连接的任意一 ...
- 深入浅出TCP之半关闭与CLOSE_WAIT
转自:https://www.2cto.com/net/201309/243585.html(相关链接) 深入浅出TCP之半关闭与CLOSE_WAIT 终止一个连接要经过4次握手.这由TCP的半关闭( ...
- 5 Linux网络编程基础API
5.1 socket地址API 大端字节序(网络序):高位在低址,低位在高址 小端字节序(主机序):低位在低址,高位在高址 判断,利用联合的特性: #include <iostream> ...
- TCP之半关闭与CLOSE_WAIT
终止一个连接要经过4次握手.这由TCP的半关闭(half-close)造成的.既然一个TCP连接是全双工(即数据在两个方向上能同时传递,可理解为两个方向相反的独立通道),因此每个方向必须单独地进行关闭 ...
随机推荐
- 并发编程 - 线程 - 1.开启线程的两种方式/2.进程与线程的区别/3.Thread对象的其他属性或方法/4.守护线程
1.开启线程的两种方式: 进程,线程: 进程只是用来把资源集中到一起(进程只是一个资源单位,或者说资源集合)而线程才是cpu上的执行单位) 1.同一个进程内的多个线程共享该进程内的地址资源 2.创建线 ...
- MyBatis 工作流程及插件开发
1. MyBatis 框架分层架构 2. MyBatis 工作流程 获取 SqlSessionFactory 对象: 解析配置文件(全局映射,Sql映射文件)的每一个信息,并保存在Configurat ...
- django 前端传文件到后台项目目录
Html端: <form action="/student/upload" method="POST" enctype="multipart/f ...
- LightOJ1003---Drunk(拓扑排序判环)
One of my friends is always drunk. So, sometimes I get a bit confused whether he is drunk or not. So ...
- POJ 3171
题目大意: 给定一个区间范围[M,E],接下来有n行输入.每行输入三个数值:T1,T2,S,表示覆盖区间[T1,T2] 的代价为S,要求你求出覆盖区间[M,E]的最小代价,假设不能覆盖, ...
- mysql监控优化(二)主从复制
复制解决的基本问题是让一台服务器的数据和其他服务器保持同步.一台主服务器的数据可以同步到多台从服务器上.并且从服务器也可以被配置为另外一台服务器的主库.主库和从库之间可以有多种不同的组合方式. MyS ...
- jQuery对象和DOM对象之间的转换
jQuery对象不能使用DOM对象的任何方法,DOM对象也不能使用jQuery对象的任何方法.在需要使用时需要对其进行转换. jQuery对象前使用"$",这不是必须的,不这么使用 ...
- c++中字符串反转的3种方法
第一种:使用algorithm中的reverse函数 #include <iostream> #include <string> #include <algorithm& ...
- 微信小程序组件toast
操作反馈toast:官方文档 Demo Code: var toastNum = 2 var pageData = {} pageData.data = {} for(var i = 0; i < ...
- 【U3D】脚本引用的类,如何显示在编辑器界面
有时候,我们的类里面会组合其他功能模块 如何让这些功能类的值在编辑器界面出现呢? 1:引用类的访问类型必须是Public 2: 类必须声明为可序列化的,即在类头加入以下声明 [System.Seria ...