mylinuxer

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

使用多线程时,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.

 

posted on 2016-02-05 17:11  mylinuxer  阅读(383)  评论(0编辑  收藏  举报