close与shutdown系统调用
2016-02-05 17:11
309 查看
使用多线程时,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.
使用多进程时,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.
相关文章推荐
- 【Gym 100610A】Alien Communication Masterclass
- Codeforces Round #278 (Div. 2) B. Candy Boxes (模拟,数学)
- Django 笔记 URL导向
- 分治法(浅谈分治法)
- 【slighttpd】基于lighttpd架构的Server项目实战(6)—预备知识之Http
- 迁移eclipse项目至Android studio遇到的问题
- Linux必须要学会的常用命令
- pipe未命名管道
- WORDPRESS第二课/WP-ADMIN目录文件
- 问题:所有播放器打开均提示网络加载失败,有时候浏览器还打不开网页
- IRP
- c++ 中this底层
- 用顺序统计树(红黑树扩张)解决逆序对POJ1804
- redis使用(四):C 同步接口
- J2EE开发框架搭建(2) - springmvc4 + spring4 + hibernate4 整合
- String、StringBuffer和StringBuilder的深入解析
- LinuxC常用数据结构及函数总结
- WORDPRESS第一课根目录文件说明(ROOT)
- Java模板引擎 FreeMarker
- Mysql 服务无法启动 服务没有报告任何错误