使用多线程时,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系统调用的更多相关文章

  1. shutdown系统调用

    /* * Shutdown a socket. */ SYSCALL_DEFINE2(shutdown, int, fd, int, how) { int err, fput_needed; stru ...

  2. TCP层shutdown系统调用的实现分析

    概述 shutdown系统调用在tcp层会调用两个函数,对于ESTABLISHED状态需要调用tcp_shutdown关闭连接,对于LISTEN和SYN_SENT状态则需要以非阻塞模式调用tcp_di ...

  3. 关于socket的关闭:close和shutdown

    通过两种方式可以关闭一个socket:close和shutdown.直接调用close关闭socket存在以下两个问题: 1. close只是将socket 描述字的访问计数减1,仅当描述字的访问计数 ...

  4. Socket shutdown close简要分析

    shutdown 系统调用关闭连接的读数据通道  写数据通道 或者 读写数据通道: 关闭读通道:丢弃socket fd 读数据以及调用shutdown 后到达的数据: 关闭写通道:不同协议处理不同:t ...

  5. TCP/IP详解--连接状态变迁图CLOSE_WAIT

    终止一个连接要经过4次握手.这由TCP的半关闭(half-close)造成的.既然一个TCP连接是全双工(即数据在两个方向上能同时传递,可理解为两个方向相反的独立通道),因此每个方向必须单独地进行关闭 ...

  6. Linux 高性能服务器编程——TCP协议详解

    问题聚焦:     本节从如下四个方面讨论TCP协议:     TCP头部信息:指定通信的源端端口号.目的端端口号.管理TCP连接,控制两个方向的数据流     TCP状态转移过程:TCP连接的任意一 ...

  7. 深入浅出TCP之半关闭与CLOSE_WAIT

    转自:https://www.2cto.com/net/201309/243585.html(相关链接) 深入浅出TCP之半关闭与CLOSE_WAIT 终止一个连接要经过4次握手.这由TCP的半关闭( ...

  8. 5 Linux网络编程基础API

    5.1   socket地址API 大端字节序(网络序):高位在低址,低位在高址 小端字节序(主机序):低位在低址,高位在高址 判断,利用联合的特性: #include <iostream> ...

  9. TCP之半关闭与CLOSE_WAIT

    终止一个连接要经过4次握手.这由TCP的半关闭(half-close)造成的.既然一个TCP连接是全双工(即数据在两个方向上能同时传递,可理解为两个方向相反的独立通道),因此每个方向必须单独地进行关闭 ...

随机推荐

  1. hashCode和equals方法的区别与联系

    hashCode()方法和equal()方法的作用其实一样,在Java里都是用来对比两个对象是否相等: (1)equal()相等的两个对象他们的hashCode()肯定相等,也就是用equal()对比 ...

  2. vue项目中批量打印二维码

    前提:项目中要打印的二维码为后台返回,批量选择后,点击打印,先打开二维码预览界面,再执行打印. 以下代码中 codePicList为选中的二维码数组.重点css:page-break-after:al ...

  3. Java8 中的时间和日期 API

    1. 日期和时间概述 LocalDate,LocalTime,LocalDateTime类的实例是不可变的对象,分别表示使用 ISO-8601 日历系统 的日期,时间,日期和时间;它们提供了简单的日期 ...

  4. Redis vs Mongo vs mysql

    Redis 和 Mongo 都属于 No-SQL类型的数据库,他们的区别,联系是什么呢?看了一些文章,特总结如下. Redis 最大的特点是,快!为什么快,因为他将大量的东西存储在了memory中.但 ...

  5. 简单的SQL注入学习

    引贴: http://blog.163.com/lucia_gagaga/blog/static/26476801920168184648754/ 首先需要编写一个php页面,讲php页面放入/opt ...

  6. java通过URL获取文本内容

    原文地址https://www.cnblogs.com/myadmin/p/7634262.html public static String readFileByUrl(String urlStr) ...

  7. AngularJS 笔记系列(五)过滤器 filter

    过滤器是用来格式化给用户展示的数据的. 在 HTML 中的模板绑定符号{{}} 内通过|符号来调用过滤器. 大写:{{ name | uppercase }} 也可以在 JS 中进行调用$filter ...

  8. centos7编译安装Python3.6(与2.7并存)

    首先去官网下载python3.6 https://www.python.org/ 环境准备:#yum install openssl-devel bzip2-devel expat-devel gdb ...

  9. OS X 10.9 Mavericks下如何安装Command Line Tools(命令行工具)

    OS X 10.9 Mavericks下如何安装Command Line Tools(命令行工具) 今天OS X 10.9 Mavericks正式发布,免费更新,立即去更新看看效果. 不过升级后安装命 ...

  10. 4. MySQL必知必会之排序检索数据-ORDER BY

    本章将讲授如何使用SELECT语句的ORDER BY子句,根据需要排序检 索出的数据. 1. 排序数据