当前位置:网站首页>Fd: file descriptor

Fd: file descriptor

2022-06-21 08:13:00 Fly&L

FD Introduce

file descriptors (FD) File descriptor , File handle .Linux The system treats everything as a file , When the process opens an existing file or creates a new file , The kernel returns a file descriptor to the process , File descriptors are indexes created by the kernel to efficiently manage opened files , Used to point to an open file , All execution I/O The system call of the operation will pass through the file descriptor .

FD The role of : Processes use file descriptors to manage open files , programmatic FD Is the symbol of the document ( Link to the file ), Eliminate the long and absolute path .

0   Is keyboard read only 
1,2  A terminal can be understood as a screen 
3+   It's a document , Can read but write 

 Insert picture description here
How to understand /proc The directory under the file ?
The so-called process , It is the data only available when the machine is running , That is, all in memory . The data in the memory is written to /proc/* Under this catalog .
/proc Catalog understanding

# testing tail Of pid
┌──(rootkali)-[/proc]
└─# ps -aux | grep tail
root        4387  0.0  0.0   5800   568 pts/0    S+   11:33   0:00 tail -f stat
root        4424  0.0  0.0   6408   648 pts/1    S+   11:36   0:00 grep --color=auto tail
# View the limits of the process , stay Max open files You can see that a process can create at most fd The quantity of is 1024
┌──(rootkali)-[/proc]
└─# cat /proc/4387/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             7647                 7647                 processes 
Max open files            1024                 1048576              files     
Max locked memory         260805632            260805632            bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       7647                 7647                 signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us                                                                            
# The process takes up 17 A descriptor 
┌──(rootkali)-[/proc]
└─# cat /proc/4387/limits | wc -l
17
 View the number of open file descriptors used by the current system 
┌──(rootkali)-[/proc]
└─# cat /proc/sys/fs/file-nr     
5792    0       9223372036854775807
# The first number indicates the number of open file descriptors allocated by the system , The second one is no longer used , The third term is file-max
 The most open processes fd
 see :ulimit  -n
 Temporary settings : ulimit  -n  10000

FD And handle
Check the article
In depth understanding of FD

原网站

版权声明
本文为[Fly&L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210811412482.html