i节点(inode)和文件描述符(file descriptor)的区别和联系

Linux文件描述符原理与Shell重定向实现 文件描述符是Linux系统编程的核心概念之一,作为进程访问I/O资源的抽象句柄,其底层通过文件描述符表、文件表和inode表三级结构实现。理解描述符的复制(dup/dup2)与继承机制,是掌握Shell重定向、管道等高级特性的基础。本文以minishell开发为例,详解如何通过文件描述符操作实现输入输出重定向、描述符传递等关键功能,并探讨epoll监控、非阻塞IO等高性能场景下的最佳实践。 阅读详情

   inode 或i节点是指对文件的索引。如一个系统,所有文件是放在磁盘或flash上,就要编个目录来说明每个文件在什么地方,有什么属性,及大小等。就像书本的目录一样,便于查找和管理。这目录是操作系统需要的,用来找文件或叫管理文件。许多操作系统都用到这个概念,如linux, 某些嵌入式文件系统等。当然,对某个系统来说,有许多i节点。所以对i节点本身也是要进行管理的。

    在linux中,内核通过inode来找到每个文件,但一个文件可以被许多用户同时打开或一个用户同时打开多次。这就有一个问题,如何管理文件的当前位移量,因为可能每个用户打开文件后进行的操作都不一样,这样文件位移量也不同,当然还有其他的一些问题。所以linux又搞了一个文件描述符(file descriptor)这个东西,来分别为每一个用户服务。每个用户每次打开一个文件,就产生一个文件描述符,多次打开就产生多个文件描述符,一一对应,不管是同一个用户,还是多个用户。该文件描述符就记录了当前打开的文件的偏移量等数据。所以一个i节点可以有0个或多个文件描述符。多个文件描述符可以对应一个i节点。

view plaincopy to clipboardprint?
struct inode {   
  struct list_headi_hash;   
  struct list_headi_list;   
  struct list_headi_dentry;   
  struct list_headi_dirty_buffers;   
  unsigned longi_ino; /*每一个inode都有一个序号,经由super block结构和其序号,我们可以很轻易的找到这个inode。*/  
  atomic_t i_count; /*在Kernel里,很多的结构都会记录其reference count,以确保如果某个结构正在使用,它不会被不小心释放掉,i_count就是其reference count。*/  
  kdev_t i_dev; /* inode所在的device代码 */  
  umode_t i_mode; /* inode的权限 */  
  nlink_t i_nlink; /* hard link的个数 */  
  uid_t i_uid; /* inode拥有者的id */  
  gid_t i_gid; /* inode所属的群组id */  
  kdev_t i_rdev; /* 如果inode代表的是device的话,那此字段将记录device的代码 */  
  off_t i_size; /* inode所代表的档案大小 */  
  time_t i_atime; /* inode最近一次的存取时间 */  
  time_t i_mtime; /* inode最近一次的修改时间 */  
  time_t i_ctime; /* inode的产生时间 */  
  unsigned long i_blksize; /* inode在做IO时的区块大小 */  
  unsigned long i_blocks; /* inode所使用的block数,一个block为512 byte*/  
  unsigned long i_version; /* 版本号码 */  
  unsigned short i_bytes;   
  struct semaphore i_sem;   
  struct rw_semaphore i_truncate_sem;   
  struct semaphore i_zombie;   
  struct inode_operations *i_op;   
  struct file_operations *i_fop;/* former ->i_op->default_file_ops */  
  struct super_block *i_sb; /* inode所属档案系统的super block */  
  wait_queue_head_t i_wait;   
  struct file_lock *i_flock; /* 用来做file lock */  
  struct address_space *i_mapping;   
  struct address_space i_data;   
  struct dquot *i_dquot [MAXQUOTAS];   
  /* These three should probably be a union */  
  struct pipe_inode_info *i_pipe;   
  struct block_device *i_bdev;   
  struct char_device *i_cdev;   
  unsigned longi_dnotify_mask; /* Directory notify events */  
  struct dnotify_struct *i_dnotify; /* for directory notifications */  
  unsigned long i_state; /* inode目前的状态,可以是I_DIRTY,I_LOCK和 I_FREEING的OR组合 */  
  unsigned int i_flags; /* 记录此inode的参数 */  
  unsigned char i_sock; /* 用来记录此inode是否为socket */  
  atomic_t i_write count;   
  unsigned int i_attr_flags; /* 用来记录此inode的属性参数 */  
  __u32 i_generation;   
  union {   
  struct minix_inode_info minix_i;   
  struct ext2_inode_info ext2_i;   
  struct ext3_inode_info ext3_i;   
  struct hpfs_inode_info hpfs_i;   
  struct ntfs_inode_info ntfs_i;   
  struct msdos_inode_info msdos_i;   
  struct umsdos_inode_info umsdos_i;   
  struct iso_inode_info isofs_i;   
  struct sysv_inode_info sysv_i;   
  struct affs_inode_info affs_i;   
  struct ufs_inode_info ufs_i;   
  struct efs_inode_info efs_i;   
  struct romfs_inode_info romfs_i;   
  struct shmem_inode_info shmem_i;   
  struct coda_inode_info coda_i;   
  struct smb_inode_info smbfs_i;   
  struct hfs_inode_info hfs_i;   
  struct adfs_inode_info adfs_i;   
  struct qnx4_inode_info qnx4_i;   
  struct reiserfs_inode_info reiserfs_i;   
  struct bfs_inode_info bfs_i;   
  struct udf_inode_info udf_i;   
  struct ncp_inode_info ncpfs_i;   
  struct proc_inode_info proc_i;   
  struct socketsocket_i;   
  struct usbdev_inode_info usbdev_i;   
  struct jffs2_inode_infojffs2_i;   
  void *generic_ip;   
  } u;   
  }; 

 

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/wangchaoxjtuse/archive/2010/11/26/6036816.aspx

STM32项目分享:智能家居语音系统 (资料分享见文末)基于STM32的智能家居语音系统温湿度采集:系统通过DHT11模块采集温湿度烟雾监测:通过MQ-2模块采集环境中烟雾浓度光照强度采集:通过BH1750传感器采集环境光照强度窗帘控制:通过步进电机转动模拟窗帘控制风扇控制:通过继电器和指示灯模拟风扇驱动照明控制:通过继电器和指示灯模拟照明驱动蜂鸣器报警:环境烟雾异常情况下蜂鸣器报警OLED显示:显示温湿度、光照强度和烟雾浓度APP功能:使用机智云APP,包括功能有控制照明灯和风扇开关、显示当前温湿度信息。 阅读详情

相关推荐

Linux DRM驱动实战:手把手教你用drmModeSetCrtc显示纯色画面(附完整代码)

本文提供了一份完整的Linux DRM驱动实战指南,手把手教你使用drmModeSetCrtc在屏幕上显示纯色画面。文章详细解析了从打开设备、获取资源、创建帧缓冲区到最终提交画面的完整调用流程,并附带了可直接编译运行的完整代码示例,帮助开发者快速上手Linux图形底层开发。

weixin_29216353的博客 512

文件描述符(file descriptor)详解,让你彻底了解计算机系统!

文件描述符是一个与输入/输出资源相关的整数,也可以被称为文件句柄(file handle)、文件指针(file pointer)或文件引用(file reference)。简单来说,它是操作系统为了管理 I/O 操作而维护的一个表中的索引,代表着系统中打开的文件的一个“门牌号”。这个表通常被称为文件描述符表(file descriptor table),其中每个条目描述了一个打开的文件,并包含文件的类型、读写位置以及其他状态信息。我们可以通过文件描述符来引用这些打开的文件,进行文件读写操作。

m0_72410588的博客 7555

HarmonyOS NEXT 开发者预览版Beta招募应知测试

本次HarmonyOS NEXT 开发者预览版 Beta 招募活动为开发者预览版尝鲜升级,主要供开发者进行应用调测使用,除部分系统应用外,其他所有应用将被清除,因此在进行HarmonyOS NEXT 开发者预览版升级前,需进行数据备份。通过应知测试,并提交了参加HarmonyOS NEXT 开发者预览版招募 Beta 活动的报名信息,就会立刻审核通过并且收到新版本。手机在参加HarmonyOS NEXT 开发者预览版 Beta 招募活动前,需要对应机型升级到招募要求对应的基线版本,并预留内存空间。

长久公子的博客 8649

文件描述符

有了文件描述符之后,由于global file table处于内核空间中,用户即使拥有fd,也无法得到实际文件对象的地址,除非把fd作为系统调用的参数来使用,如此一来,控制权又回到了内核手中,也便达到了权限控制的目的。进程级的描述符表的每一个条目记录了当前进程所有打开的文件的文件描述符,进程之间相互独立,例如一个进程使用了文件描述符99,另一个进程也可以用99。标准错误和标准输出可以重定向到同一个地方,比如指令中的&1表示的就是标准输出,2>&1的含义就是重定向标准错误到标准输出表示的数据流中。

Shared_wisdom的博客 4763

WindTerm 安装使用教程

WindTerm是一款Github上开源的 SSH 终端工具,它是完全可以比肩MobaXterm工具的。

m0_69576880的博客 4031

FPGA可重构技术

介绍FPGA 可重构技术的实现方法,包括全局重构和部分重构

航天领域资深码农,型号经验丰富,一线干货分享 1989

文件描述符(通俗易懂)

该文章主要是针对面试做大致的了解,不做详细介绍!!!一、具体结构说明:1、一个进程能够同时打开多个文件,对应需要多个文件描述符,所以需要用一个文件描述符表对文件描述符进行管理;通常默认大小为1024,也即能容纳1024个文件描述符;2、文件描述符表中0、1、2三个位置对应的文件描述符固定不变,标准输入、标准输出、标准错误;3、当打开一个文件时,内核会自动在文件描述符表中寻找一个空闲且最小的文件描述符;4、同一个文件可以被多次打开,但是每打开一次都需要一个新的文件描述符;5、已经被占用的文件描述符在被释放后,

热爱数据库的小胖 1万+

内存管理(二)——内存分段

内存分段

weixin_43844995的博客 2693

文件描述符(File Descriptor)简介

维基百科:文件描述符在形式上是一个非负整数。实际上,它是一个索引值,指向内核为每一个进程所维护的该进程打开文件的记录表。当程序打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件描述符。在程序设计中,一些涉及底层的程序编写往往会围绕着文件描述符展开。 一、文件描述符概念   Linux 系统中,把一切都看做是文件,当进程打开现有文...

weixin_34119545的博客 1234

让 ABAP 程序天生可翻译:Text Symbols 与 Text Pool 从入门到工程化落地

ABAP 国际化实践:Text Symbols 的工程价值与落地方法 摘要: 本文系统阐述了 ABAP 开发中 Text Symbols 的核心价值与实践方法。通过解耦程序逻辑与语言文本,Text Symbols 实现了代码国际化,避免了硬编码带来的维护难题。文章详细介绍了 Text Pool 结构、两种引用方式(独立引用 TEXT-001 和附着式 '(001)'),以及 SE38 和 SE63 的翻译流程。特别强调最大长度预留、术语统一等工程实践,并提供了 READ TEXTPOOL 自动化检查方案。最

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 239

【推荐100个unity插件】Unity URP(通用渲染管线)的基于物理的天地和预计算大气散射——UnityPhysicallyBasedSkyURP

本文介绍了Unity URP(通用渲染管线)中基于物理的天地和预计算大气散射的实现方法。该插件提供物理天空、大气散射、高度雾效、动态天空反射和环境光等功能,要求Unity 2022.3及以上版本,支持着色器模型3.5+。使用步骤包括:添加渲染器功能、配置Volume组件(天空、雾效等),并建议太阳强度设为3、曝光为0作为初始设置。插件已在GitHub和Gitee开源,附带详细配置截图和效果展示。文末推荐了多个Unity开发相关专栏,涵盖游戏开发全领域知识。作者向宇提供了博客链接,欢迎交流学习问题。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 1228

Linux - 文件描述符 | 文件系统 | 软硬链接

Linux - 文件描述符 | 文件系统 | 软硬链接

2302_79539362的博客 2417

数字后端:版图基础seal ring

seal ring结构是为了防止划片或封装对芯片造成破坏,从而在芯片与划片道(scribe line)之间添加的一圈保护环

m0_61544122的博客 1万+

linux系统编程之基础必备(三):文件描述符file descriptor与inode的相关知识

每个进程在Linux内核中都有一个task_struct结构体来维护进程相关的 信息,称为进程描述符(Process Descriptor),而在操作系统理论中称为进程控制块 (PCB,Process Control Block)。task_struct中有一个指针(struct files_struct *files; )指向files_struct结构体,称为文件 描述符表,其中每个表项包

Meditation 2万+

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Linux文件描述符(file descriptor)和文件指针

文件描述符(file descriptor): 在linux系统中,设备也是以文件的形式存在,要对该设备进行操作就必须先打开这个文件,打开这个文件就会获得这个文件描述符,它是个很小的正整数,它是一个索引值,指向内核为每一个进程所维护的、该进程打开文件的记录表。 文件描述符的优点:兼容POSIX标准,许多Linux和 UNIX系统调用都依赖于它。文件描述符的缺点:不能移植...

qq469617582的博客 820

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

什么是文件描述符(File Descriptor)

什么是文件描述符(File Descriptor)通俗类比Linux 中的标准文件描述符验证文件描述符1. 查看进程打开的文件描述符2. 通过重定向改变指向为什么需要区分 stdout 和 stderr?实际例子深入理解 `&1` 中的 `&`对比两种写法验证区别文件描述符的本质(底层视角)高级玩法:自定义文件描述符实用例子:临时保存标准输出总结要点一句话定义:文件描述符是一个非负整数,是操作系统内核为了管理已打开的文件或资源而分配给进程的"索引号"或"句柄"。# 打开文件并分配描述符 3。

CharlesYuangc的博客 342

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

linux系统文件描述符file descriptor与inode的相关知识

转自: http://blog.youkuaiyun.com/simba888888/article/details/8806654   每个进程在Linux内核中都有一个task_struct结构体来维护进程相关的 信息,称为进程描述符(Process Descriptor),而在操作系统理论中称为进程控制块 (PCB,Process Control Block)。task_struct中

右上角同学的专栏 546

【linux学习】深入理解linux文件I/O,从C标准库到内核态

本文深入解析了Linux文件I/O机制,从C标准库I/O与系统调用的关系入手,揭示了文件描述符的本质是进程文件描述符表的数组下标。通过分析重定向原理,指出其本质是修改内核文件指针指向。文章还探讨了缓冲区的特性及其在fork时的表现差异,解释了"一切皆文件"的设计哲学通过VFS层实现操作系统层面的多态。最后介绍了磁盘物理结构到文件系统逻辑结构的抽象过程,全面阐述了Linux文件I/O从用户态到内核态的完整实现机制。这些知识是理解操作系统文件管理和进行系统编程的重要基础。

z20050930的博客 356

Linux文件操作:从open()系统调用到文件描述符原理

在Linux系统编程中,文件操作是最基础且核心的技术之一。文件描述符作为进程与内核交互的关键抽象,本质上是一个整数值索引,指向内核维护的文件表项。通过open()系统调用,程序可以获取文件描述符,进而进行读写等操作。理解文件描述符的工作原理,对于掌握Linux I/O多路复用、进程间通信等高级特性至关重要。在实际工程中,合理使用O_NONBLOCK非阻塞标志和O_CLOEXEC等特性,能显著提升程序性能和安全性。本文深入分析从用户态open()调用到内核VFS处理的完整链路,揭示文件描述符背后的精妙设计。

weixin_34242331的博客 353

Linux文件描述符深度解析:从内核原理到高并发实战

在操作系统和系统编程领域,I/O(输入/输出)管理是核心基础。其原理在于操作系统通过统一的抽象接口来管理各类资源,实现高效、安全的访问。这一技术价值在于为上层应用提供了简洁一致的编程模型,同时为高性能并发处理奠定了基础。其应用场景广泛,涵盖文件读写、网络通信、进程间交互等。本文聚焦于Linux中的关键抽象——文件描述符(fd),深入剖析其作为进程访问I/O资源统一入口的本质。通过解读进程描述符表、系统打开文件表和inode表这三层内核数据结构,揭示fd从创建到关闭的生命周期。文章结合epoll、socket

weixin_30700977的博客 401

Linux VFS 深度解析(三):struct file(文件对象)

Linux VFS 深度解析(三):struct file(文件对象)摘要 struct file 是 Linux VFS 中表示进程打开文件实例的核心数据结构,与表示磁盘文件的 inode 不同,它记录了文件打开时的运行时状态。关键点包括: 本质区别:inode 表示持久化文件元数据,struct file 表示打开实例(含偏移量、访问模式等) 生命周期:从 open() 到 close(),内存中动态创建销毁 多实例性:同一文件可被多次打开,每个打开操作创建独立 struct file 核心字段:

siny_hj的博客 902
上一篇: Fedora16 安装相关
下一篇: 使用iperf测试网络性能
evenness
博客等级 码龄15年 99粉丝 8原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值