浅析dup()和dup2()函数

原子操作与程序中的重定向: dup()与dup2()函数 阅读详情

前言

  在linux下,一切皆文件。当文件被打开时,会返回文件描述符用于操作该文件,从shell中运行一个进程,默认会有3个文件描述符存在(0、1、2);)0表示标准输入,1表示标准输出,2表示标准错误。一个进程当前有哪些打开的文件描述符可以通过/proc/进程ID/fd目录查看。

  今天,我们主要说两个用于复制文件描述符的函数dup()和dup2()。

dup()、dup2()函数

函数原形

#include <unistd.h> 
int dup(int oldfd); 
int dup2(int oldfd, int newfd);

功能

  复制文件描述符,使多个文件描述符指向同一个文件。

返回值

 成功:dup函数返回当前系统可用的最小整数值。
    dup2函数返回第一个不小于newfd的整数值。也就是分为两种情况:
    ①、如果newfd已经打开,则先将其关闭,再复制文件描述符。
    ②、如果newfd等于oldfd,则dup2返回newfd, 而不关闭它。

 失败:均返回-1,并设置errno。

注意:通过dup和dup2创建的文件描述符并不继承原文件描述符的属性。比如close-on-exec和non-blocking

示例程序

dup.c

//测试dup函数
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main()
{
    int fd = open("a.txt", O_RDWR | O_CREAT);
    if(fd == -1)
    {
        perror("open");
        exit(1);
    }

    printf("file open fd = %d\n", fd);

    // 找到进程文件描述表中第一个可用的文件描述符
    // 将参数指定的文件复制到该描述符后,返回这个描述符
    int ret = dup(fd);  //使ret和fd指向同一个文件
    if(ret == -1)
    {
        perror("dup");
        exit(1);
    }

    printf("dup fd = %d\n", ret);

    char* buf = "hello";
    char* buf1 = " world\n";

    write(fd, buf, strlen(buf));
    write(ret, buf1, strlen(buf1));

    close(fd);


    return 0;
}

dup2.c

//测试dup2函数

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main()
{
    int fd = open("b.txt", O_RDWR | O_CREAT);
    if(fd == -1)
    {
        perror("open");
        exit(1);
    }

int fd1 = open("a.txt", O_RDWR);
if(fd1 == -1)
{
    perror("open");
    exit(1);
}

printf("fd = %d\n", fd);
printf("fd1 = %d\n", fd1);

int ret = dup2(fd, fd1);  //让fd1和fd同时指向b.txt
if(ret == -1)
{
    perror("dup2");
    exit(1);
}
printf("current fd = %d\n", ret);
char* buf = "hello ";
char* buf1 = " world!";
write(fd, buf, strlen(buf));
write(fd1, buf1 , strlen(buf1));

close(fd);
close(fd1);


return 0;

}

CGI服务器的原理

  在CGI程序,当浏览器使用post方法提交表单数据时,CGI读数据是从标准输入stdin,写数据是写到标准输出stdout(C中使用printf)。按照我们正常的理解,printf的输出应该在终端显示,这是什么原因呢?也是和我们今天介绍的这两个复制文件描述符的函数有关。我们先来看一下代码:

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int main( int argc, char* argv[] )
{
    if( argc <= 2 )
    {
        printf( "usage: %s ip_address port_number\n", basename( argv[0] ) );
        return 1;
    }
    const char* ip = argv[1];
    int port = atoi( argv[2] );

    struct sockaddr_in address;
    bzero( &address, sizeof( address ) );
    address.sin_family = AF_INET;
    inet_pton( AF_INET, ip, &address.sin_addr );
    address.sin_port = htons( port );

    int sock = socket( PF_INET, SOCK_STREAM, 0 );
    assert( sock >= 0 );

    int ret = bind( sock, ( struct sockaddr* )&address, sizeof( address ) );
    assert( ret != -1 );

    ret = listen( sock, 5 );
    assert( ret != -1 );

    struct sockaddr_in client;
    socklen_t client_addrlength = sizeof( client );
    int connfd = accept( sock, ( struct sockaddr* )&client, &client_addrlength );
    if ( connfd < 0 )
    {
        printf( "errno is: %d\n", errno );
    }
    else
    {
        close( STDOUT_FILENO );
        dup( connfd );
    //dup2(connfd, STDOUT_FILENO);
        printf( "hello world!\n" );
        close( connfd );
    }

    close( sock );
    return 0;
}

  在上述代码中,我们先关闭标准输出STDOUT_FILENO(1),然后通过dup函复制connfd,因为dup函数返回的系统第一个可用的文件描述符,所以其返回的是1,这样一来,服务器输出到标准输出的内容就会被客户端所获得而不是输出到服务器的终端上。这就是CGI服务器的基本工作原理。

【linuxC语言】dup、dup2函数 在Linux环境下,dup、dup2以及原子操作都是用于文件描述符管理和处理的重要工具。这些功能提供了对文件描述符进行复制和原子操作的能力,使得在多线程或多进程环境中更加安全和高效地进行文件操作。通过本文的介绍,我们了解到在Linux环境下,dup、dup2以及原子操作在文件描述符管理和处理中扮演着重要的角色。它们提供了对文件描述符进行复制和原子操作的功能,使得文件操作更加灵活、高效和安全。深入理解并熟练掌握这些功能,对于编写高性能、可靠的Linux程序是非常重要的。 阅读详情

相关推荐

5G LDPC编码实战:从校验矩阵到Matlab代码实现(附完整源码)

本文深入解析5G NR标准中的LDPC编码工程实现,聚焦于从3GPP协议中的QC-LDPC校验矩阵到高效Matlab代码的转换。文章详细阐述了基础矩阵(BG1/BG2)选择、提升因子确定以及利用双对角结构的快速编码算法,并提供了完整的、可优化的Matlab源码,旨在帮助通信算法工程师和开发者快速构建5G LDPC编码仿真原型,为硬件实现奠定基础。

table的专栏 382

dup函数详解

dup操作 功能:复制文件描述符,重定向输入输出。 函数: #include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); 返回值: 成功:dup函数返回当前系统可用的最小整数值。 dup2函数返回第一个不小于newfd的整数值,分两种情况: 1. 如果newfd已经打开,则先将其关闭,再复制文件描述符; 2. 如果newfd等于oldfd,,则dup2函数返回newfd,而不关闭它。 失

weixin_42864391的博客 1万+

别再重启了!Win11开机卡死/间歇性卡顿的终极排查与修复指南(附免费工具)

本文提供Win11开机卡死和间歇性卡顿的终极排查与修复指南,涵盖从后台进程清理到驱动优化、系统组件修复及硬件监控的全方位解决方案。通过专业工具和详细步骤,帮助用户彻底解决Win11卡顿问题,无需重启或重装系统。

weixin_31102231的博客 782

函数dup

文章目录函数dup/dup2 函数dup/dup2   函数dup和函数dup2都用于复制一个文件描述符,其原型如下: #include &lt;unistd.h&gt; int dup(int fd); int dup2(int fd1, int fd2); 两个函数在调用成功时都会返回一个新的描述符,若出错则会返回-1。   对于函数dup而言,dup会返回一个当前可用描述符中最小的一个...

小腿跑乱刀的博客 2298

Ubuntu22.04安装搜狗输入法踩坑实录:从依赖报错到完美解决的完整指南

本文详细解析了在Ubuntu 22.04系统上安装搜狗拼音输入法的完整流程,从解决依赖报错到配置fcitx框架,再到最终优化使用体验。针对常见的dpkg安装错误和fcitx冲突问题,提供了实用的解决方案和命令,帮助用户顺利完成安装并享受流畅的中文输入体验。

palm99的专栏 981

开源低场MRI系统构建:从原理到三天实现

磁共振成像(MRI)作为现代医学影像的核心技术,其高场强系统存在成本和技术门槛问题。低场MRI通过开源硬件和模块化设计实现技术民主化,采用永磁体替代超导磁体可大幅降低系统复杂度。本文以H型永磁体设计为例,结合MaRCoS开源控制库和PyPulseq脉冲序列工具,展示了如何快速构建教育级MRI系统。关键技术包括遗传算法优化的匀场方案、CNC加工的梯度线圈,以及基于Red Pitaya的SDR控制架构。这种轻量化方案特别适合医学物理教学和脉冲序列开发验证,为MRI技术在资源有限地区的普及提供了新思路。

weixin_30470643的博客 459

Linux系统编程——dup() 重定向函数

这篇文章讲的是linux系统编程中的重定向函数,这个函数的作用是将一个文件描述符指向另一个文件描述符,有点像指针的作用,比如:fd2 指向 fd1,你改变 fd2 的文件内容,就可以直接改变fd1的内容,fd2是指向fd1的。

weixin_67452474的博客 2566

别再为PT100测温发愁了!手把手教你用ADS1247+STM32搞定高精度温度采集(附完整代码)

本文详细介绍了如何使用ADS1247与STM32构建高精度PT100测温系统,涵盖硬件设计、SPI配置、温度计算及调试技巧。通过24位ADC和内置PGA,实现0.1℃级精度,适用于工业自动化和医疗设备。附完整代码和常见问题解决方案,助你快速掌握高精度温度采集技术。

weixin_42524703的博客 348

dup()与dup2()的浅析

文章目录前言定义详解close then openopen - close - dup -closeopen - dup2 - close参考: 前言 关于dup()和dup2()的使用在Linux系统编程中是十分重要的一环,但关于dup2()的使用总有一种雾蒙蒙的感觉,本文会从dup()说起,希望可以带领大家走过迷雾 文中代码片中代码仅供逻辑参考 因本人水平有限,若文中有何纰漏,恳请各位斧正 定义 详解 dup()的使用与open(),close()函数的联系十分密切 思考一下,我们如何完

lin3ux的博客 767

AGX Orin载板设计避坑指南:电源时序、存储选型与高速接口布局

在嵌入式系统开发中,核心模块的载板设计直接决定产品稳定性。以Jetson AGX Orin为例,其外围电路需解决电源树规划、上电时序控制、启动介质选型及高速信号完整性等基础问题。电源时序错误可能导致模组保护无输出,QSPI与NVMe的启动配置影响系统引导,而PCIe、USB等高速接口的阻抗与布局则关乎链路可靠性。这些工程细节广泛存在于边缘计算、AI推理盒子等场景。本文聚焦AGX Orin载板设计,从电源、存储、调试到高速接口,分享实战中易忽略的时序、余量及布局要点,助你避开首板即翻车的陷阱。

weixin_34159110的博客 394

基于Dify实现对Excel的数据分析

在dify部署完成后,大家就可以基于此进行各种应用场景建设,目前dify支持聊天助手(包括对话工作流)、工作流、agent等模式的场景建设,我们在日常工作中经常会遇到各种各样的数据清洗、格式转换处理、数据统计成图等数据分析工作,本次主要基于对话工作流模式对Excel文件、csv文件进行解析处理,并进行成图等数据分析工作。主要用到的插件有LLM节点,文档提取器、参数提取器、自定义代码节点、echart插件等。实现解析Excel数据,经过上述不同节点的处理分析流程,最终实现数据统计图展示。

hhue2007的专栏 1万+

浅析open函数O_CLOEXEC模式和fcntl函数FD_CLOEXEC选项

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML序列图和流程图 离线写博客 导入导出Markdown文件 丰富的快捷键 快捷键 加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

编程笔记 - codingnote 1032

【即插即用模块】卷积篇 | CVPR 2025 | LSConv:大核捕全局,小核提速度,替换 3×3 卷积/自注意力,精度效率双飙升

文章摘要: LSConv是一种新型卷积模块,采用"大核感知+小核聚合"策略,在轻量级视觉任务中表现出色。该模块由两部分组成:7×7深度可分离卷积(LKP)捕捉全局信息,动态3×3卷积(SKA)实现高效特征聚合。相比传统卷积和自注意力机制,LSConv在降低计算量的同时提升了精度,尤其适合高分辨率视觉任务。实验表明,在轻量化模型中用LSConv替代3×3卷积或自注意力,可显著减少计算量并提高准确率。模块支持即插即用,提供Triton优化实现,可直接集成到现有卷积或Transformer架构

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1133

[APUE] 第三章部分习题

APUE第三章部分习题

追寻梦想的青春 2630

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

深度学习工具包 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")

APUE 第三章习题 3.2 浅析

题目描述:编写一个与3.12节中dup2功能相同的函数,要求不能调用fcntl函数,并且有正确的出错处理。 题目分析:既然不能使用fcntl函数,那么我们就需要使用其他函数来达到类似的目的,这里列举出所有我们需要使用的函数。 1、 open函数:这里我们不应该指定一个文件描述符并尝试复制它,因为实际中我们不能知道我们指定的文件描述符就一定是合法的,这个文件描述符可能未被使用,如果这样的话就会...

weixin_34024034的博客 210

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

UNIX环境高级编程---文件描述符浅析

UNIX环境高级编程---文件描述符浅析最近看到一本书叫《UNIX环境高级编程》,网上称这本书被誉为UNIX编程“圣经”,对所有不同层次UNIX/LINUX程序员是一本不可缺少的参考书。自己最近恰好看到GLIB中IOChannel这部分,关于linux的IO这块很不清楚,先研究完这本书再说。文件描述符是一个小的非负整数,内核用以标识一个特定进程正在存访的文件。当内核打开一个现存文件或创建一个新文件...

weixin_33770878的博客 83

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

APUE 习题 3.2 浅析

题目描述:编写一个与3.12节中dup2功能相同的函数,要求不能调用fcntl函数,并且有正确的出错处理。 题目分析:既然不能使用fcntl函数,那么我们就需要使用其他函数来达到类似的目的,这里列举出所有我们需要使用的函数。 1、 open函数:这里我们不应该指定一个文件描述符并尝试复制它,因为实际中我们不能知道我们指定的文件描述符就一定是合法的,这个文件描述符可能未被使用,如果这样的话就会...

weixin_34234721的博客 123

keepalived源码浅析——Notify

Notify 模块作用是执行系统外部脚本 Notify.h 源码 Notify.c的头文件 #ifndef _NOTIFY_H #define _NOTIFY_H /* system includes */ extern int system_call(char *cmdline); extern void closeall(int fd); extern int notify

wdt3385的专栏 2316

linux — 浅析文件描述符 文件表项 v节点表项

浅析文件描述符 文件表项 v节点表项符 文件描述符在Linux编程里随处可见,设备读写,网络通信,进程通信. 可是文件描述符到底是什么? 文件描述符是一个简单的整数,用以标明每一个 被进程所打开的文件和socket. 第一个打开的文件时0,第二个是1,以此类推. linux操作系统通常给每个进程能打开的文件数量强加一个限制. 文件描述符

阿亮的博客 2748

浅析linux下open函数O_CLOEXEC模式和fcntl函数FD_CLOEXEC选项

关于open函数O_CLOEXEC模式,fcntl函数FD_CLOEXEC选项,总结为如下几点: 1.调用open函数O_CLOEXEC模式打开的文件描述符在执行exec调用新程序中关闭,且为原子操作。 2.调用open函数不使用O_CLOEXEC模式打开的文件描述符,然后调用fcntl 函数设置FD_CLOEXEC选项,效果和使用O_CLOEXEC选项open函数相同,但分别调用

左雪菲的专栏 9123

浅析android下propt怎么通过init进程传递和glibc库函数的添加

<br />http://blog.chinaunix.net/u1/38994/showart_1170108.html<br />浅析android下propt怎么通过init进程传递和glibc库函数的添加<br /><br /> adb shell<br /># printenv<br /># getprop 获取所有java层propt<br /># setprop wifi. interface eth0 设置"wifi.interface" 对应的数值为eth0<br />

为了忘却的记忆 1204

浅析内核中用户进程的创建

进程创建是一个非常复杂的过程,涉及到很多的技术细节,以及与内核中的很多子系统的交互等,要完整的讨论到各种情况不太可能,这里只以用户空间调用fork()创建进程为例来进行讨论。   fork()系统调用对应的内核实现为sys_fork(),sys_fork()是对do_fork()的简单封装,sys_fork()的任务是从处理器寄存器中提取由用户空间提供的信息,do_fork()负责进程的复制。f

Justlinux2010的专栏 2102
上一篇: frok 与 vfork
下一篇: 详解二叉树的非递归遍历
z_ryan
博客等级 码龄9年 255粉丝 43原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值