CINXE.COM

文件描述符fd和0 & 1 & 2的含义(stdin..)-腾讯云开发者社区-腾讯云

<!DOCTYPE html><html lang="zh" munual-autotracker-init="" qct-uid="" qct-pv-id="u7kZj6jcQpTeb1nI3ve9O" qct-ip="8.222.208.146"><head><meta charSet="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="format-detection" content="telephone=no"/><title>文件描述符fd和0 &amp; 1 &amp; 2的含义(stdin..)-腾讯云开发者社区-腾讯云</title><meta name="subject" content="其他-空类-系统,其他-空类-重定向,其他-空类-stdin,其他-空类-进程,其他-空类-数据"/><meta name="subjectTime" content="2024-11-15 08:31:52"/><meta name="articleSource" content="B"/><meta name="magicSource" content="N"/><meta name="authorType" content="Z"/><meta name="productSlug" content="none"/><meta name="keywords" content="系统,重定向,stdin,进程,数据"/><meta name="description" content="在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:"/><meta property="og:title" content="文件描述符fd和0 &amp; 1 &amp; 2的含义(stdin..)-腾讯云开发者社区-腾讯云"/><meta property="og:description" content="在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:"/><meta property="og:image" content="https://cloudcache.tencentcs.com/open_proj/proj_qcloud_v2/gateway/shareicons/cloud.png"/><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover"/><link rel="dns-prefetch" href="//qccommunity.qcloudimg.com"/><link rel="dns-prefetch" href="//ask.qcloudimg.com"/><link rel="dns-prefetch" href="//cloudcache.tencentcs.com"/><link rel="canonical" href="https://cloud.tencent.com/developer/article/2465765"/><meta name="next-head-count" content="20"/><link rel="stylesheet" href="https://imgcache.qq.com/open_proj/proj_qcloud_v2/gateway/portal/css/base.css"/><link rel="stylesheet" href="https://cloudcache.tencentcs.cn/qcloud/ui/cloud-community/build/base/base-202411191502.css"/><style type="text/css"> .rno-markdown p * { white-space: pre-wrap; word-break: break-all; } .tea-overlay { z-index: 99999!important; } </style><link rel="stylesheet" href="https://cloudcache.tencentcs.cn/qcloud/ui/cloud-community/build/Article/Article-202411141616.css"/><link rel="stylesheet" href="https://cloudcache.tencent-cloud.cn/qcloud/draft-master/dist/draft-master-v2.0.123.d4s2ddo9sb.css"/><link rel="stylesheet" href="https://qccommunity.qcloudimg.com/tc_player/release/tcplayer.min.css"/><script src="https://tam.cdn-go.cn/aegis-sdk/latest/aegis.min.js"></script><script> if (Aegis) { new Aegis({ id: 'dWlmyFvjDnalkbZO8q', env: 'production', onError: true, pagePerformance: true, reportAssetSpeed: true, api: { reportRequest: true, resHeaders: ['x-req-id'], }, reportApiSpeed: true, beforeRequest: function (data) { // load js failed if (data.logType === 'log') { if (data.logs.level === '32' && data.logs.msg.indexOf('google') > -1) return false; } var ignoreKeys = [ 'Script error', 'chrome-extension', 'qq.com', 'queryWeappQrcodeStatus', 'login/ajax/info', 'woa.com', 'trafficCollect.php', 'google', 'dscache', 'act-api', 'set_qc_cookie', 'opc.cloud.tencent.com', 'uc_gre_ad_buss', 'eb.xcj.pub', 'UCShellJava', '/developer/labs/quick/loader', 'edgeImmersiveReaderDOM', 'sendBeacon', 'error-decoder.html', 'qcloud-community-track.min.js' ]; var alarmMsg = [data.logs.url, data.logs.msg].join('|'); for (var i = 0; i < ignoreKeys.length; i++) { if (alarmMsg.indexOf(ignoreKeys[i]) != -1) return false; } if (/bot|wechatdevtools|spider/i.test(navigator.userAgent)) { return false; } if (location.hostname.indexOf('cloud.tencent.') === -1) { return false; } }, }); } </script><link rel="preload" href="https://qccommunity.qcloudimg.com/community/_next/static/css/15864e0bbdb1e0dc.css" as="style"/><link rel="stylesheet" href="https://qccommunity.qcloudimg.com/community/_next/static/css/15864e0bbdb1e0dc.css" data-n-g=""/><link rel="preload" href="https://qccommunity.qcloudimg.com/community/_next/static/css/ea44d1213c71c27d.css" as="style"/><link rel="stylesheet" href="https://qccommunity.qcloudimg.com/community/_next/static/css/ea44d1213c71c27d.css" data-n-p=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/webpack-4b3f70494b513c95.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/framework-bae252e255276064.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/main-05fe3e9ebcc3b2a5.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/pages/_app-8122a2af2c111715.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/1001-2e1adf6d088ee502.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/900-71009a4f9d961db7.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/743-1dcf6b0fcebaa4b8.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/2191-2e402fdba497a1f2.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/9966-3be3b289121a48f8.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/552-eb32205d1d3e17d7.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/4031-e3e3905dc88f3f92.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/2391-e1b083c8280dce67.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/4117-79ab33e3944a99db.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/1200-586c8913d338875f.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/5305-6c6287588b89e496.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/9987-50fa00be52ea0a59.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/6995-71865d1b014e8b9a.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/9179-724eee5c06230b86.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/5039-d174dd09ec91e23e.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/4298-ecf78077c366b99e.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/787-c20307b99a7c9e79.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/6474-2c0e1629f7738528.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/5650-649e162b184be571.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/9626-02550f5f9bc8270d.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/3346-a1ce44eb71f29cdb.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/1794-4524fda45251d496.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/3270-57ce21952a43da02.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/8583-79f5e98099bd4de0.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/8876-194359d4cea91f27.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/chunks/pages/article/%5BarticleId%5D-df9140f92647ede0.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/A33mNyh0oM2Hz_SodWz7T/_buildManifest.js" defer=""></script><script src="https://qccommunity.qcloudimg.com/community/_next/static/A33mNyh0oM2Hz_SodWz7T/_ssgManifest.js" defer=""></script></head><body class=""><div id="__next"><script src="https://dscache.tencent-cloud.cn/ecache/qcstat/qcloud/qcloudStatApi.js"></script><script src="https://qccommunity.qcloudimg.com/common/exposure-plugin-4.1.15.min.js"></script><script src="https://qccommunity.qcloudimg.com/community-track/qcloud-community-track.min.js"></script><div class="cdc-responsive-layout" aegis-first-screen-timing="true" qct-area="文章详情页"><div class="cdc-article-page2 cdc-global"><div class="cdc-sticky-header mod-sticky-header is-hidden" style="left:0"><div id="community-top-header-product-container"></div><div class="cdc-sticky-header__inner"><div class="cdc-sticky-header__main"><div class="mod-sticky-header__main"><div class="mod-sticky-header__author"><span class="cdc-avatar circle"><a class="cdc-avatar__inner" style="background-image:url(https://developer.qcloudimg.com/avatar/26311.png)" href="/developer/user/11276311" target="_blank"></a></span><div class="author-info"><a class="author-info__name" href="/developer/user/11276311" target="_blank"><span class="name-text">ljw695</span></a></div></div><div class="mod-sticky-header__split"></div><div class="mod-sticky-header__title"><div class="mod-sticky-header__title-content"><h2 class="title-text">文件描述符fd和0 &amp; 1 &amp; 2的含义(stdin..)</h2></div></div></div></div><div class="cdc-sticky-header__extra"><div class="mod-sticky-header__operates"><button class="cdc-btn mod-sticky-header__operate btn-focus cdc-btn--primary"><i class="add-icon"></i><span>关注作者</span></button></div></div></div></div><div class="cdc-m-guider-banner"><div class="cdc-m-guider-banner__guide-mvp is-detail-page"><div class="cdc-m-guider-banner__guide-mvp-text">前往小程序,Get<em>更优</em>阅读体验!</div><div class="cdc-m-guider-banner__guide-mvp-btn">立即前往</div></div></div><div class="cdc-header cdc-header--block" track="导航"><div class="cdc-header__placeholder"></div><div class="cdc-header__inner"><div id="community-top-header-product-container"></div><div class="cdc-header__top"><div class="cdc-header__top-left"><a href="/?from=20060&amp;from_column=20060" target="_blank" class="cdc-header__top-logo" hotrep="" track="腾讯云官网入口"><i>腾讯云</i></a><div class="cdc-header__top-line"></div><a href="/developer" class="cdc-header__top-logo community"><i>开发者社区</i></a><div class="cdc-header__activity"><div id="cloud-header-product-container"></div></div></div><div class="cdc-header__top-operates"><a href="/document/product?from=20702&amp;from_column=20702" target="_blank" class="cdc-header__link">文档</a><a href="/voc/?from=20703&amp;from_column=20703" target="_blank" class="cdc-header__link">建议反馈</a><a href="https://console.cloud.tencent.com?from=20063&amp;from_column=20063" target="_blank" class="cdc-header__link" track-click="{&quot;areaId&quot;:102001,&quot;subAreaId&quot;:1}">控制台</a><div class="cdc-header__account"><div class="cdc-header__account-inner"><button class="cdc-btn cdc-header__account-btn cdc-btn--primary">登录/注册</button></div></div></div></div><div class="cdc-header__bottom"><div class="cdc-header__bottom-nav"><a href="/developer" class="cdc-header__bottom-home">首页</a><div class="cdc-header__nav-list"><div class="cdc-header__nav-item">学习</div><div class="cdc-header__nav-item">活动</div><div class="cdc-header__nav-item">专区</div><div class="cdc-header__nav-item">工具</div></div><a href="/tvp?from=20154&amp;from_column=20154" class="cdc-header__tvp" target="_blank">TVP</a><div class="cdc-header__activity"><a class="cdc-header__activity-tit" href="/act?from=20061&amp;from_column=20061" target="_blank">最新优惠活动<div class="cdc-badge"><div class="cdc-badge-inner"><div class="cdc-badge-text"></div></div></div></a></div><div id="community-header-product-container"></div></div><div class="cdc-header__bottom-operates"><div class="cdc-header__search"><div class="cdc-search__wrap"><div class="cdc-search"><span class="cdc-search__text">文章/答案/技术大牛</span><button class="cdc-search__btn">搜索<i class="cdc-search__i search"></i></button></div><div class="cdc-search__dropdown"><div class="cdc-search__bar"><input type="text" class="cdc-search__bar-input" placeholder="文章/答案/技术大牛" value=""/><div class="cdc-search__bar-btns"><button class="cdc-search__btn">搜索<i class="cdc-search__i search"></i></button><button class="cdc-search__btn">关闭<i class="cdc-search__i clear"></i></button></div></div></div></div></div><div class="cdc-header__create"><span class="cdc-header__create-btn not-logged"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:16px;height:16px"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path d="M14.2466 12.0145C14.1698 13.6258 12.8381 14.9131 11.2129 14.9131H11.1579H4.0927H4.03772C2.4125 14.9131 1.08014 13.6258 1.00334 12.0145H1V11.8668V4.07213V4.04627V3.89922H1.00334C1.08014 2.28732 2.4125 1 4.03772 1H9.6473V1.00069H10.0786L8.7688 2.10773H8.43888H7.7916H6.37904H4.03772C2.97234 2.10773 2.10445 2.9777 2.10445 4.04629V4.41869V4.4472V6.39498V11.4269V11.4309V11.8668C2.10445 12.9354 2.97234 13.8053 4.03772 13.8053H6.37904H8.87153H11.2129C12.2782 13.8053 13.1461 12.9355 13.1461 11.8668V11.466V11.454V9.5181V6.39364L14.2506 5.3051V11.8668V12.0145H14.2466ZM10.4324 7.15226L9.63146 7.99761C9.36577 8.2693 8.69326 8.95104 8.48066 9.17631C8.26726 9.40288 8.09039 9.58901 7.95061 9.73544C7.81079 9.88188 7.72667 9.96597 7.70083 9.98656C7.63321 10.0488 7.55703 10.1144 7.47022 10.1846C7.38412 10.2542 7.29404 10.3099 7.20063 10.3516C7.10722 10.4007 6.97072 10.459 6.79049 10.5305C6.61028 10.6001 6.42213 10.6676 6.22468 10.7339C6.02792 10.8002 5.84109 10.8571 5.66484 10.9061C5.48795 10.9538 5.3561 10.9863 5.2693 11.0009C5.08977 11.0214 4.96988 10.993 4.90956 10.9168C4.84931 10.8405 4.83276 10.7107 4.85924 10.5312C4.87315 10.4331 4.9043 10.292 4.95468 10.1078C5.00431 9.92297 5.05802 9.7315 5.11431 9.53341C5.1713 9.33526 5.22629 9.15179 5.27926 8.98484C5.33297 8.8179 5.37599 8.7026 5.40978 8.64032C5.44953 8.54357 5.49463 8.45413 5.54495 8.37399C5.59465 8.29379 5.66616 8.20503 5.75965 8.10766C5.79934 8.06588 5.89281 7.96649 6.03988 7.81018C6.18624 7.65311 6.80114 7.02774 7.02104 6.79783L7.75117 6.03524L8.56212 5.1899L10.6345 3.02466L12.5214 4.93874L10.4324 7.15226ZM13.816 3.58581C13.7166 3.68987 13.6272 3.78064 13.5483 3.85883C13.4694 3.93703 13.4006 4.0066 13.3423 4.06686C13.276 4.13643 13.2144 4.19738 13.1561 4.24903L11.2785 2.33569C11.3785 2.24025 11.4965 2.12565 11.6336 1.99115C11.7707 1.85668 11.8854 1.75061 11.9761 1.67242C12.0934 1.57708 12.2133 1.51013 12.3385 1.47109C12.4525 1.43529 12.5644 1.41805 12.6751 1.41876H12.7056C12.7665 1.42139 12.8268 1.42729 12.8851 1.43724C12.8838 1.4366 12.8811 1.43724 12.8798 1.4366C12.8811 1.4366 12.8838 1.4366 12.8851 1.43724C13.1376 1.48428 13.4019 1.62009 13.6265 1.83743C13.7511 1.95871 13.8524 2.09382 13.9259 2.23296C14.0346 2.43834 14.0863 2.65304 14.0763 2.8491C14.0763 2.87294 14.0783 2.89748 14.0783 2.92201C14.0783 3.03529 14.0571 3.14789 14.0154 3.26055C13.9737 3.37314 13.9067 3.48185 13.816 3.58581Z" fill="#0052D9"></path></svg></span></span>发布<span class="cdc-svg-icon-con cdc-header__create-btn-arrow"><span class="cdc-svg-icon" style="width:16px;height:16px"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path d="M8.16377 4L9.57798 5.41421L14.5277 10.364L13.1135 11.7782L8.1638 6.829L3.21402 11.7782L1.7998 10.364L8.16377 4Z"></path></svg></span></span></span></div></div></div></div></div><div class="cdc-m-sticky-header is-hidden is-sticky"><div class="cdc-m-sticky-header__placeholder"></div><div class="cdc-m-sticky-header__main"><div class="cdc-m-sticky-header__con"><div class="cdc-m-sticky-header__trigger"></div><div class="cdc-m-header-article__menu"><div class="cdc-m-header-article__menu-mask"></div><div class="cdc-m-header-article__menu-side"><div class="cdc-m-header__sidebar"><div class="cdc-m-header__sidebar-top"><i class="cdc-m-header__sidebar-top__logo"></i><span class="cdc-m-header__sidebar-top__back"></span></div><div class="cdc-m-header__sidebar-menus"><a href="/developer" class="cdc-m-header__sidebar-menu link">首页</a><div class="tpm1-collapse"><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">学习</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">活动</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">专区</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">工具</div></header></div></div><a href="/tvp?from=20154&amp;from_column=20154" class="cdc-m-header__sidebar-menu link">TVP</a><a class="cdc-m-header__sidebar-activity" href="/act?from=20061&amp;from_column=20061" target="_blank">最新优惠活动<div class="cdc-badge"><div class="cdc-badge-inner"><div class="cdc-badge-text"></div></div></div></a></div><div class="cdc-m-header__sidebar-back"><a href="/?from=20060&amp;from_column=20060" class="cdc-m-header__sidebar-back__link"><i></i><span>返回腾讯云官网</span></a></div></div></div></div><div class="cdc-m-sticky-header__author"><span class="cdc-avatar large circle" style="cursor:unset"><span class="cdc-avatar__inner" style="background-image:url(https://developer.qcloudimg.com/avatar/26311.png)"></span></span><div class="cdc-m-sticky-header__author-name">ljw695</div></div></div><div class="cdc-m-sticky-header__extra"><div class="cdc-m-sticky-header__extra-icon"><i class="extra-search"></i></div><div class="cdc-m-sticky-header__extra-icon"><i class="extra-share"></i></div><div class="cdc-m-sticky-header__extra-operate"><div class="cdc-m-sticky-header__extra-icon"><i class="extra-man"></i></div></div></div></div></div><div class="cdc-m-header-article"><div class="cdc-m-header-article__placeholder"></div><div class="cdc-m-header-article__content"><div class="cdc-m-header-article__main"><div class="cdc-m-header-article__con"><div class="cdc-m-header-article__trigger"></div><div class="cdc-m-header-article__menu"><div class="cdc-m-header-article__menu-mask"></div><div class="cdc-m-header-article__menu-side"><div class="cdc-m-header__sidebar"><div class="cdc-m-header__sidebar-top"><i class="cdc-m-header__sidebar-top__logo"></i><span class="cdc-m-header__sidebar-top__back"></span></div><div class="cdc-m-header__sidebar-menus"><a href="/developer" class="cdc-m-header__sidebar-menu link">首页</a><div class="tpm1-collapse"><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">学习</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">活动</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">专区</div></header></div><div class="tpm1-collapse__panel"><header class="tpm1-collapse__panel-hd"><div class="tpm1-collapse__panel-title">工具</div></header></div></div><a href="/tvp?from=20154&amp;from_column=20154" class="cdc-m-header__sidebar-menu link">TVP</a><a class="cdc-m-header__sidebar-activity" href="/act?from=20061&amp;from_column=20061" target="_blank">最新优惠活动<div class="cdc-badge"><div class="cdc-badge-inner"><div class="cdc-badge-text"></div></div></div></a></div><div class="cdc-m-header__sidebar-back"><a href="/?from=20060&amp;from_column=20060" class="cdc-m-header__sidebar-back__link"><i></i><span>返回腾讯云官网</span></a></div></div></div></div></div><div class="cdc-m-header-article__title"><div class="cdc-m-header-article__title-logo"></div></div><div class="cdc-m-header-article__extra"><div class="cdc-m-header-article__extra-icon"><i class="extra-search"></i></div><div class="cdc-m-header-article__extra-operate"><div class="cdc-m-header-article__extra-icon"><i class="extra-man"></i></div></div></div></div></div></div><div class="cdc-global__main"><div class="cdc-article__body"><div class="cdc-layout"><div class="cdc-layout__main"><div class="cdc-crumb mod-crumb"><div class="cdc-crumb__inner"><a class="cdc-crumb__item" href="/developer">社区首页</a><span class="cdc-crumb__split"> &gt;</span><a class="cdc-crumb__item" href="/developer/column">专栏</a><span class="cdc-crumb__split"> &gt;</span><span class="cdc-crumb__item current">文件描述符fd和0 &amp; 1 &amp; 2的含义(stdin..)</span></div></div><div class="mod-article-content"><div class="mod-header2"><div class="mod-header2__top"><div class="mod-header2__title"><h1 class="title-text">文件描述符fd和0 &amp; 1 &amp; 2的含义(stdin..)</h1></div></div><div class="mod-article-source header"><div class="mod-article-source__main"><div class="mod-article-source__avatar"><img src="https://developer.qcloudimg.com/avatar/26311.png" alt="作者头像"/></div><div class="mod-article-source__detail"><div class="mod-article-source__name"><span>ljw695</span></div></div><button class="cdc-btn mod-article-source__operate cdc-btn--primary"><span><i></i>关注</span></button></div></div><div class="mod-header2__bottom"><div class="mod-header2__detail"><div class="mod-header2__date"><span class="date-text">发布<!-- -->于 <!-- -->2024-11-15 08:31:52</span></div><div class="mod-header2__infos"><div class="cdc-icon__list"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:16px;height:16px"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><g id="icon-view" transform="translate(0.000000, 3.000000)" fill="currentcolor" fill-rule="nonzero"><path d="M15.885,4.68036 C14.9951,3.57569 11.7987,-0.004272 7.99883,-0.004272 C4.19895,-0.004272 1.02302,3.57569 0.112682,4.68036 C0.040058,4.77107 0.000488281,4.88381 0.000488281,5 C0.000488281,5.1162 0.040058,5.22894 0.112682,5.31964 C1.00767,6.42432 4.20407,10.0043 7.99883,10.0043 C11.7936,10.0043 14.9951,6.42432 15.885,5.31964 C15.9576,5.22894 15.9972,5.1162 15.9972,5 C15.9972,4.88381 15.9576,4.77107 15.885,4.68036 Z M7.99883,8.97632 C4.93029,8.97632 2.25555,6.25043 1.17644,4.99745 C2.25555,3.74446 4.95586,1.01857 7.99883,1.01857 C11.0418,1.01857 13.7421,3.74446 14.8314,4.99745 C13.7421,6.25043 11.0418,8.97632 7.99883,8.97632 Z" id="形状"></path><path d="M7.97304,2.55286 C7.49865,2.55286 7.03491,2.69353 6.64046,2.95709 C6.24602,3.22065 5.93859,3.59525 5.75704,4.03354 C5.5755,4.47182 5.528,4.95409 5.62055,5.41937 C5.7131,5.88465 5.94154,6.31203 6.27699,6.64748 C6.61244,6.98293 7.03982,7.21137 7.5051,7.30392 C7.97038,7.39647 8.45265,7.34897 8.89093,7.16743 C9.32922,6.98588 9.70382,6.67845 9.96738,6.28401 C10.2309,5.88956 10.3716,5.42582 10.3716,4.95143 C10.3716,4.31529 10.1189,3.7052 9.66909,3.25538 C9.21927,2.80556 8.60918,2.55286 7.97304,2.55286 Z M7.97304,6.32716 C7.70095,6.32716 7.43496,6.24647 7.20872,6.09531 C6.98249,5.94414 6.80616,5.72928 6.70203,5.4779 C6.59791,5.22652 6.57066,4.94991 6.62374,4.68304 C6.67683,4.41617 6.80785,4.17104 7.00025,3.97864 C7.19265,3.78625 7.43778,3.65522 7.70465,3.60214 C7.97151,3.54905 8.24813,3.5763 8.49951,3.68042 C8.75089,3.78455 8.96575,3.96088 9.11692,4.18712 C9.26808,4.41335 9.34877,4.67934 9.34877,4.95143 C9.35012,5.13295 9.31553,5.31295 9.247,5.48104 C9.17846,5.64913 9.07734,5.802 8.94946,5.93084 C8.82158,6.05967 8.66946,6.16192 8.50188,6.2317 C8.3343,6.30147 8.15457,6.33739 7.97304,6.33739 L7.97304,6.32716 Z" id="形状"></path></g></svg></span><span class="cdc-svg-icon-text">79</span></span><span class="cdc-svg-icon-con is-comment"><span class="cdc-svg-icon" style="width:16px;height:16px"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M8 13.414L5.58594 11H2V3H14V11H10.4141L8 13.414ZM5.17175 12L8 14.8282L10.8282 12H15V2H1V12H5.17175ZM4 6C3.44775 6 3 6.44769 3 7C3 7.55231 3.44775 8 4 8C4.55225 8 5 7.55231 5 7C5 6.44769 4.55225 6 4 6ZM7 7C7 6.44769 7.44775 6 8 6C8.55225 6 9 6.44769 9 7C9 7.55231 8.55225 8 8 8C7.44775 8 7 7.55231 7 7ZM12 6C11.4478 6 11 6.44769 11 7C11 7.55231 11.4478 8 12 8C12.5522 8 13 7.55231 13 7C13 6.44769 12.5522 6 12 6Z"></path></svg></span><span class="cdc-svg-icon-text">0</span></span></div></div><div class="mod-header2__date is-mobile"><span class="date-text">发布<!-- -->于 <!-- -->2024-11-15 08:31:52</span></div></div><div class="mod-header2__operates"><div class="mod-header2__operate"><span class="cdc-svg-icon-con is-operate"><span class="cdc-svg-icon" style="width:16px;height:16px"><svg width="16" height="16" viewBox="0 0 16 16" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.21101 2.54545C8.80733 1.81818 7.79814 1.81818 7.39446 2.54545L1.94481 12.3636C1.54113 13.0909 2.04573 14 2.85308 14H13.7524C14.5597 14 15.0643 13.0909 14.6607 12.3636L9.21101 2.54545ZM2.85308 12.9091L8.30273 3.09091L13.7524 12.9091H2.85308ZM8.00037 6H9.00037V10H8.00037V6ZM8.00037 11H9.00037V12H8.00037V11Z" fill="currentcolor"></path></svg></span><span class="cdc-svg-icon-text">举报</span></span></div></div></div><div class="mod-header2__special"><div class="cdc-special-guide"><span><i class="cdc-special-guide-icon"></i>文章被收录于专栏:</span><a class="cdc-special-guide-name">ljw</a></div></div></div><div class="mod-content"><div class="mod-content__markdown"><div><div class="rno-markdown new-version rno-"><p>重定向的实质</p><figure class=""><div class="rno-markdown-img-url" style="text-align:center"><div class="rno-markdown-img-url-inner" style="width:100%"><div style="width:100%"><img src="https://developer.qcloudimg.com/http-save/yehe-11276311/d59c92d55316e9990d723371aea0cb60.png" alt="" style="width:100%"/></div></div></div></figure><p>1和2的区别</p><figure class=""><div class="rno-markdown-img-url" style="text-align:center"><div class="rno-markdown-img-url-inner" style="width:100%"><div style="width:100%"><img src="https://developer.qcloudimg.com/http-save/yehe-11276311/c5ea139d7d79fa2c18d189372f4c9014.png" alt="" style="width:100%"/></div></div></div></figure><figure class=""><div class="rno-markdown-img-url" style="text-align:center"><div class="rno-markdown-img-url-inner" style="width:100%"><div style="width:100%"><img src="https://developer.qcloudimg.com/http-save/yehe-11276311/033cc2100ef7e724bfa18fa28e3f530c.png" alt="" style="width:100%"/></div></div></div></figure><p>在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:</p><h5 id="d8bm0" name="%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E7%9A%84%E5%90%AB%E4%B9%89">文件描述符的含义</h5><ol class="ol-level-0"><li> <strong>标准输入</strong>(stdin) <ul class="ul-level-1"><li><strong>描述符:</strong> <code>0</code></li><li><strong>用途:</strong> 接收输入数据,通常是来自键盘的用户输入。</li><li><strong>使用场景:</strong> 例如,当你在命令行中运行程序时,可以通过键盘输入数据,这些数据会被程序读取。</li></ul></li><li> <strong>标准输出</strong>(stdout) <ul class="ul-level-1"><li><strong>描述符:</strong> <code>1</code></li><li><strong>用途:</strong> 用于输出数据,通常是显示在终端上的信息。</li><li><strong>使用场景:</strong> 例如,<code>echo &quot;Hello, World!&quot;</code> 会将字符串输出到标准输出,即命令行界面。</li></ul></li><li> <strong>标准错误</strong>(stderr) <ul class="ul-level-1"><li><strong>描述符:</strong> <code>2</code></li><li><strong>用途:</strong> 用于输出错误信息,通常也会显示在终端上,但可以与标准输出分开重定向。</li><li><strong>使用场景:</strong> 例如,运行一个不存在的命令会产生错误信息,这些信息会输出到标准错误。</li></ul></li></ol><h5 id="1hhon" name="%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B">使用示例</h5><p>以下是一些文件描述符的常见使用示例:</p><h6 id="8ko4j" name="1.-%E5%9F%BA%E6%9C%AC%E8%BE%93%E5%87%BA">1. 基本输出</h6><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0">bash</code></pre></div></div><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0"># 将字符串输出到标准输出 echo &quot;This is standard output&quot;</code></pre></div></div><h6 id="3873i" name="2.-%E9%94%99%E8%AF%AF%E8%BE%93%E5%87%BA">2. 错误输出</h6><p>bash</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0"># 使用不正确的命令产生错误信息 some_nonexistent_command</code></pre></div></div><h6 id="7v3v2" name="3.-%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA">3. 重定向标准输出</h6><p>将标准输出重定向到文件:</p><p>bash</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0"># 将输出重定向到文件 output.txt echo &quot;This will be saved to a file&quot; &gt; output.txt</code></pre></div></div><h6 id="1t38c" name="4.-%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF">4. 重定向标准错误</h6><p>将标准错误重定向到文件:</p><p>bash</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0"># 将输出重定向到文件 output.txt echo &quot;This will be saved to a file&quot; &gt; output.txt</code></pre></div></div><h6 id="7cj4u" name="5.-%E5%90%8C%E6%97%B6%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%E5%92%8C%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF">5. 同时重定向标准输出和标准错误</h6><p>将标准输出和标准错误同时重定向到同一个文件:</p><p>bash</p><div class="rno-markdown-code"><div class="rno-markdown-code-toolbar"><div class="rno-markdown-code-toolbar-info"><div class="rno-markdown-code-toolbar-item is-type"><span class="is-m-hidden">代码语言:</span>javascript</div></div><div class="rno-markdown-code-toolbar-opt"><div class="rno-markdown-code-toolbar-copy"><i class="icon-copy"></i><span class="is-m-hidden">复制</span></div></div></div><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript"><code class="language-javascript" style="margin-left:0"># 将标准输出和标准错误都重定向到 same_output_and_error.txt echo &quot;This will go to the file&quot; &gt; same_output_and_error.txt 2&gt;&amp;1</code></pre></div></div><h5 id="f9c85" name="%E7%9B%B8%E5%85%B3%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8">相关系统调用</h5><p>在编程中,你还可以使用系统调用来操作文件描述符,以下是一些常用的:</p><ul class="ul-level-0"><li><code>open()</code>: 打开文件并返回文件描述符。</li><li><code>read()</code>: 从文件描述符中读取数据。</li><li><code>write()</code>: 向文件描述符写入数据。</li><li><code>close()</code>: 关闭文件描述符。</li></ul><h5 id="efa80" name="%E5%B0%8F%E7%BB%93">小结</h5><p>文件描述符 <code>0</code>、<code>1</code> 和 <code>2</code> 用于表示标准输入、标准输出和标准错误,它们在 Linux 等类 Unix 系统中是处理输入输出的基础。通过合理地使用它们,可以方便地进行 I/O 操作和错误处理。</p><h3 id="fgcg1" name="%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E6%80%BB%E7%BB%93">文件描述符总结</h3><p>Linux中的文件描述符总结如下:</p><p>定义与用途:</p><p>文件描述符是内核为了高效管理已被打开的文件所创建的索引,是一个非负整数。 它用于代指被打开的文件,所有通过I/O操作的系统调用都通过文件描述符进行。</p><p>分配规则:</p><p>当进程启动时,默认会打开三个文件描述符:标准输入(stdin,文件描述符为0)、标准输出(stdout,文件描述符为1)、标准错误(stderr,文件描述符为2)。 之后打开的文件,文件描述符会从3开始依次递增,为连续的整数。</p><p>限制:</p><p>系统级限制:限制所有用户打开文件描述符的总和,可以通过sysctl命令或查看proc文件系统来查询和修改。 用户级限制:限制每个用户登录后执行的程序占用的文件描述符总数,可以通过ulimit命令查询和修改。</p><p>重定向:</p><p>文件描述符支持重定向操作,包括输出重定向、输入重定向和追加重定向。 重定向允许用户将标准输入、输出或错误重定向到文件或其他设备。</p><p>与文件对象的关系:</p><p>用户在访问文件时,系统会将文件相关信息从磁盘中加载到内存,并在内核中创建文件对象。 文件描述符用于快速定位到这些文件对象,每个文件描述符都对应一个打开文件的文件对象。</p><p>缓冲区:</p><p>每个被打开的文件都各自拥有一个缓冲区。 使用write系统调用写入数据时,数据首先被拷贝到目标文件的缓冲区中,再由操作系统决定何时将数据刷新到外设中。</p><p>一切皆文件:</p><p>在Linux下,一切皆文件,包括硬件设备、网络连接等,都可以通过文件描述符进行访问和操作。</p><p>综上所述,文件描述符是Linux内核中用于管理打开文件的一种机制,它提供了高效的文件访问方式,并支持重定向等高级功能。</p><h3 id="3r56b" name="%E4%B8%AD%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E7%9A%84%E5%85%B7%E4%BD%93%E4%BD%9C%E7%94%A8%E6%98%AF%E4%BB%80%E4%B9%88">中文件描述符的具体作用是什么</h3><p>Linux中文件描述符的具体作用主要体现在以下几个方面:</p><p>唯一标识打开的文件或资源:文件描述符是一个非负整数,由操作系统内核分配,用于唯一标识一个已经打开的文件或输入输出资源(如管道、网络连接等)。这使得进程能够准确地访问和操作特定的文件或资源。</p><p>支持多种I/O操作:文件描述符是进程与外部世界之间的桥梁。通过文件描述符,进程可以进行文件的读写操作、网络通信、进程间通信等。例如,使用read、write等系统调用进行文件内容的读取和写入,或者使用socket进行网络通信。</p><p>实现重定向:文件描述符支持重定向操作,允许用户将标准输入、标准输出或标准错误重定向到文件或其他设备。这种灵活性使得程序能够更灵活地处理输入输出数据。</p><p>管理打开的文件:每个进程都有一个文件描述符表,用于记录该进程打开的所有资源。文件描述符表对文件描述符进行管理,确保每个文件描述符都对应一个有效的打开文件或资源。同时,文件描述符的数量也是有限的,这有助于操作系统有效地管理资源。</p><p>综上所述,Linux中的文件描述符是一种高效、灵活的资源管理机制,它使得进程能够方便地访问和操作各种文件和资源。</p><h3 id="gulf" name="%E5%A6%82%E4%BD%95%E7%90%86%E8%A7%A3%E2%80%9C%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E2%80%9D">如何理解“文件描述符”</h3><p>文件描述符是:</p><p>一个非负整数,由操作系统内核分配。 用于标识和访问已经打开的文件或I/O资源(如管道、网络连接)。 通过文件描述符,进程可执行文件的读写操作、网络通信等。 文件描述符支持重定向,允许灵活处理输入输出数据。</p></div></div></div><div class="mod-content__source"><div class="mod-content__source-inner"><div class="mod-content__source-title">本文参与 <a href="/developer/support-plan" target="_blank">腾讯云自媒体同步曝光计划</a>,分享自作者个人站点/博客。</div><div class="mod-content__source-desc"> 原始发表:2024-11-05,<!-- -->如有侵权请联系 <a href="mailto:cloudcommunity@tencent.com">cloudcommunity@tencent.com</a> 删除</div></div><div class="mod-content__source-btn"><button class="cdc-btn cdc-btn--hole">前往查看</button></div></div><div class="mod-statement-m"><div class="cdc-tag__list mod-content__tags" track-click=""><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17506" target="_blank">系统</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17591" target="_blank">重定向</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/16250" target="_blank">stdin</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17332" target="_blank">进程</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17440" target="_blank">数据</a></div></div><div class="mod-content__statement"><p>本文分享自 <span>作者个人站点/博客</span> <span style="color:#0052d9;cursor:pointer">前往查看</span></p><p>如有侵权,请联系 <a href="mailto:cloudcommunity@tencent.com">cloudcommunity@tencent.com</a> 删除。</p><p class="mod-content__statement-tip">本文参与 <a href="/developer/support-plan" target="_blank">腾讯云自媒体同步曝光计划</a>  ,欢迎热爱写作的你一起参与!</p></div></div><div class="cdc-tag__list mod-content__tags" track-click=""><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17506" target="_blank">系统</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17591" target="_blank">重定向</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/16250" target="_blank">stdin</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17332" target="_blank">进程</a></div><div class="cdc-tag" track-click="" track-exposure=""><a class="cdc-tag__inner" href="/developer/tag/17440" target="_blank">数据</a></div></div></div></div><div class="mod-article-content is-pill-hidden"><div class="mod-comment"><div class="mod-relevant__title">评论</div><div class="cdc-comment-response"><div class="cdc-comment-response-single-edit not-logged"><div class="cdc-comment-response-single-edit__inner"><span class="cdc-avatar cdc-comment-response-single-edit__avatar cdc-comment__avatar circle"><span class="cdc-avatar__inner" style="background-image:url(https://qcloudimg.tencent-cloud.cn/raw/2eca91c9c29816ff056d22815949d83c.png)" target="_blank"></span></span><div class="cdc-comment-response-single-edit__main"><span>登录</span>后参与评论</div></div></div><div class="cdc-comment-response__toolbar"><div class="cdc-comment-response__number">0<!-- --> 条评论</div><div class="cdc-comment-response__segment"><div class="cdc-comment-response__segment-item is-active">热度</div><div class="cdc-comment-response__segment-item">最新</div></div></div><div class="cdc-comment-response-inner"><div class="cdc-comment-response__body"><div><div class="cdc-loading"><div class="cdc-loading__inner"><div class="cdc-loading__item one"></div><div class="cdc-loading__item two"></div><div class="cdc-loading__item three"></div></div></div></div></div></div><div class="cdc-operate-footer"><div class="cdc-operate-footer__inner"><div class="cdc-operate-footer__toggle is-logout"><div class="cdc-operate-footer__toggle-text"><span>登录 </span>后参与评论</div></div></div></div></div></div></div><div class="mod-article-content recommend"><div class="mod-relevant" qct-area="推荐阅读" qct-exposure=""><div class="mod-relevant__title recommend-read">推荐阅读</div><div class="t-divider t-divider--horizontal" style="margin-bottom:0;margin-top:10px"></div></div></div></div><div class="cdc-layout__side"><div class="cdc-personal-info2 mod-author"><div class="cdc-personal-info2__inner"><div class="cdc-personal-info2__detail"><div class="cdc-personal-info2__main"><div class="cdc-personal-info2__name"><a href="/developer/user/11276311" target="_blank" class="cdc-personal-info2__name-text"></a></div><div class="cdc-personal-info2__level"><div class="cdc-personal-info2__level-number">LV.</div><div class="cdc-emblems cdc-personal-info2__level-emblems"></div></div><div class="cdc-personal-info2__position"></div></div><div class="cdc-personal-info2__avatar"></div></div><div class="cdc-personal-info2__list"><a class="cdc-personal-info2__item" href="/developer/user/undefined/articles" target="_blank"><div class="cdc-personal-info2__item-text">文章</div><div class="cdc-personal-info2__item-number">0</div></a><a class="cdc-personal-info2__item" href="/developer/user/undefined" target="_blank"><div class="cdc-personal-info2__item-text">获赞</div><div class="cdc-personal-info2__item-number">0</div></a></div></div></div><div class="mod-sticky-act"><div class="cdc-directory is-just-commercial"><div class="cdc-directory__wrap"><div class="cdc-directory__inner"><div class="cdc-directory__hd">目录</div><div class="cdc-directory__bd"><div class="cdc-directory__bd-box"><ul class="cdc-directory__list level-1"><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-d8bm0">文件描述符的含义</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-1hhon">使用示例</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-f9c85">相关系统调用</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-efa80">小结</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-fgcg1">文件描述符总结</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-3r56b">中文件描述符的具体作用是什么</span></li><li class="cdc-directory__item"><span class="cdc-directory__target" id="menu-gulf">如何理解“文件描述符”</span></li></ul></div></div></div></div></div></div></div></div></div></div><div class="cdc-widget-global"><div class="cdc-widget-global__btn announcement"></div><div class="cdc-widget-global__btn code"><div class="cdc-widget-global__btn-tag">领券</div></div><div class="cdc-widget-global__btn top" style="visibility:hidden"></div></div><div class="cdc-footer"><div class="cdc-footer__inner"><div class="cdc-footer__main"><div class="cdc-footer__website"><ul class="cdc-footer__website-group"><li class="cdc-footer__website-column"><div class="cdc-footer__website-box"><h3 class="cdc-footer__website-title">社区</h3><ul class="cdc-footer__website-list"><li class="cdc-footer__website-item"><a href="/developer/column">技术文章</a></li><li class="cdc-footer__website-item"><a href="/developer/ask">技术问答</a></li><li class="cdc-footer__website-item"><a href="/developer/salon">技术沙龙</a></li><li class="cdc-footer__website-item"><a href="/developer/video">技术视频</a></li><li class="cdc-footer__website-item"><a href="/developer/learning">学习中心</a></li><li class="cdc-footer__website-item"><a href="/developer/techpedia">技术百科</a></li><li class="cdc-footer__website-item"><a href="/developer/zone/list">技术专区</a></li></ul></div></li><li class="cdc-footer__website-column"><div class="cdc-footer__website-box"><h3 class="cdc-footer__website-title">活动</h3><ul class="cdc-footer__website-list"><li class="cdc-footer__website-item"><a href="/developer/support-plan">自媒体同步曝光计划</a></li><li class="cdc-footer__website-item"><a href="/developer/support-plan-invitation">邀请作者入驻</a></li><li class="cdc-footer__website-item"><a href="/developer/article/1535830">自荐上首页</a></li><li class="cdc-footer__website-item"><a href="/developer/competition">技术竞赛</a></li></ul></div></li><li class="cdc-footer__website-column"><div class="cdc-footer__website-box"><h3 class="cdc-footer__website-title">资源</h3><ul class="cdc-footer__website-list"><li class="cdc-footer__website-item"><a href="/developer/specials">技术周刊</a></li><li class="cdc-footer__website-item"><a href="/developer/tags">社区标签</a></li><li class="cdc-footer__website-item"><a href="/developer/devdocs">开发者手册</a></li><li class="cdc-footer__website-item"><a href="/lab?from=20064&amp;from_column=20064">开发者实验室</a></li></ul></div></li><li class="cdc-footer__website-column"><div class="cdc-footer__website-box"><h3 class="cdc-footer__website-title">关于</h3><ul class="cdc-footer__website-list"><li class="cdc-footer__website-item"><a rel="nofollow" href="/developer/article/1006434">社区规范</a></li><li class="cdc-footer__website-item"><a rel="nofollow" href="/developer/article/1006435">免责声明</a></li><li class="cdc-footer__website-item"><a rel="nofollow" href="mailto:cloudcommunity@tencent.com">联系我们</a></li><li class="cdc-footer__website-item"><a rel="nofollow" href="/developer/friendlink">友情链接</a></li></ul></div></li></ul></div><div class="cdc-footer__qr"><h3 class="cdc-footer__qr-title">腾讯云开发者</h3><div class="cdc-footer__qr-object"><img src="https://qcloudimg.tencent-cloud.cn/raw/a8907230cd5be483497c7e90b061b861.png?imageView2/2/w/76" class="cdc-footer__qr-image" alt="扫码关注腾讯云开发者"/></div><div class="cdc-footer__qr-infos"><p class="cdc-footer__qr-info"><span class="cdc-footer__qr-text">扫码关注腾讯云开发者</span></p><p class="cdc-footer__qr-info"><span class="cdc-footer__qr-text">领取腾讯云代金券</span></p></div></div></div><div class="cdc-footer__recommend"><div class="cdc-footer__recommend-rows"><div class="cdc-footer__recommend-cell"><h3 class="cdc-footer__recommend-title">热门产品</h3><div class="cdc-footer__recommend-wrap"><ul class="cdc-footer__recommend-list"><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="https://dnspod.cloud.tencent.com?from=20064&amp;from_column=20064">域名注册</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cvm?from=20064&amp;from_column=20064">云服务器</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/tbaas?from=20064&amp;from_column=20064">区块链服务</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/mq?from=20064&amp;from_column=20064">消息队列</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/dsa?from=20064&amp;from_column=20064">网络加速</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/tencentdb-catalog?from=20064&amp;from_column=20064">云数据库</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cns?from=20064&amp;from_column=20064">域名解析</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cos?from=20064&amp;from_column=20064">云存储</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/css?from=20064&amp;from_column=20064">视频直播</a></li></ul></div></div><div class="cdc-footer__recommend-cell"><h3 class="cdc-footer__recommend-title">热门推荐</h3><div class="cdc-footer__recommend-wrap"><ul class="cdc-footer__recommend-list"><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/facerecognition?from=20064&amp;from_column=20064">人脸识别</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/tm?from=20064&amp;from_column=20064">腾讯会议</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/act/pro/enterprise2019?from=20064&amp;from_column=20064">企业云</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cdn-scd?from=20064&amp;from_column=20064">CDN加速</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/trtc?from=20064&amp;from_column=20064">视频通话</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/tiia?from=20064&amp;from_column=20064">图像分析</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cdb?from=20064&amp;from_column=20064">MySQL 数据库</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/symantecssl?from=20064&amp;from_column=20064">SSL 证书</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/asr?from=20064&amp;from_column=20064">语音识别</a></li></ul></div></div><div class="cdc-footer__recommend-cell"><h3 class="cdc-footer__recommend-title">更多推荐</h3><div class="cdc-footer__recommend-wrap"><ul class="cdc-footer__recommend-list"><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/solution/data_protection?from=20064&amp;from_column=20064">数据安全</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/clb?from=20064&amp;from_column=20064">负载均衡</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/sms?from=20064&amp;from_column=20064">短信</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/ocr?from=20064&amp;from_column=20064">文字识别</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/vod?from=20064&amp;from_column=20064">云点播</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="https://tm.cloud.tencent.com?from=20064&amp;from_column=20064">商标注册</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/solution/la?from=20064&amp;from_column=20064">小程序开发</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cat?from=20064&amp;from_column=20064">网站监控</a></li><li class="cdc-footer__recommend-item"><a class="com-2-footer-recommend-link" href="/product/cdm?from=20064&amp;from_column=20064">数据迁移</a></li></ul></div></div></div></div><div class="cdc-footer__copyright"><div class="cdc-footer__copyright-text"><p>Copyright © 2013 - <!-- -->2024<!-- --> Tencent Cloud. All Rights Reserved. 腾讯云 版权所有 </p><p>深圳市腾讯计算机系统有限公司 ICP备案/许可证号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤B2-20090059 </a><a href="https://www.beian.gov.cn/portal/index.do" target="_blank">深公网安备号 44030502008569</a></p><p>腾讯云计算(北京)有限责任公司 京ICP证150476号 |  <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">京ICP备11018762号</a> <!-- -->|<!-- --> <a href="https://www.beian.gov.cn/portal/index.do" target="_blank">京公网安备号11010802020287</a></p></div></div></div></div><div style="display:none"><a href="/developer/ask/archives.html">问题归档</a><a href="/developer/column/archives.html">专栏文章</a><a href="/developer/news/archives.html">快讯文章归档</a><a href="/developer/information/all.html">关键词归档</a><a href="/developer/devdocs/archives.html">开发者手册归档</a><a href="/developer/devdocs/sections_p1.html">开发者手册 Section 归档</a></div><div class="cdc-m-footer"><div class="cdc-m-footer__inner"><div class="cdc-m-footer__copyright"><p>Copyright © 2013 - <!-- -->2024<!-- --> Tencent Cloud.</p><p>All Rights Reserved. 腾讯云 版权所有</p></div></div></div><div class="cdc-operate-footer"><div class="cdc-operate-footer__inner"><div class="cdc-operate-footer__toggle is-logout"><div class="cdc-operate-footer__toggle-text"><span>登录 </span>后参与评论</div></div><div class="cdc-operate-footer__operations"><div class="cdc-operate-footer__operate"><i class="cdc-operate-footer__operate-icon comment"></i></div><div class="cdc-operate-footer__operate emoji"><div class="emoji-item"><span class="emoji-item-icon fight"></span></div></div><div class="cdc-operate-footer__operate"><i class="cdc-operate-footer__operate-icon book"></i></div><div class="cdc-operate-footer__operate"><i class="cdc-operate-footer__operate-icon menu"></i></div><div class="cdc-operate-footer__operate"><i class="cdc-operate-footer__operate-icon more"></i></div></div></div></div><div class="cdc-suspend-pill"><div class="cdc-suspend-pill__inner"><button class="cdc-icon-btn cdc-suspend-pill__item emoji cdc-icon-btn--text"><div class="emoji-item"><span class="emoji-item-icon like"></span></div><span class="cdc-suspend-pill__item-number">0</span></button><button class="cdc-icon-btn cdc-suspend-pill__item like cdc-icon-btn--text"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentcolor"><path fill-rule="evenodd" clip-rule="evenodd" d="M17.5 11.25C17.5 11.9404 16.9404 12.5 16.25 12.5C15.5596 12.5 15 11.9404 15 11.25C15 10.5596 15.5596 10 16.25 10C16.9404 10 17.5 10.5596 17.5 11.25Z M12.25 12.5C12.9404 12.5 13.5 11.9404 13.5 11.25C13.5 10.5596 12.9404 10 12.25 10C11.5596 10 11 10.5596 11 11.25C11 11.9404 11.5596 12.5 12.25 12.5Z M8.25 12.5C8.94036 12.5 9.5 11.9404 9.5 11.25C9.5 10.5596 8.94036 10 8.25 10C7.55964 10 7 10.5596 7 11.25C7 11.9404 7.55964 12.5 8.25 12.5Z M5 3C3.34315 3 2 4.34315 2 6V16C2 17.6569 3.34315 19 5 19H8.34311L10.5858 21.2426C11.3668 22.0237 12.6331 22.0237 13.4142 21.2426L15.6568 19H19C20.6569 19 22 17.6569 22 16V6C22 4.34315 20.6569 3 19 3H5ZM4 6C4 5.44772 4.44772 5 5 5H19C19.5523 5 20 5.44772 20 6V16C20 16.5523 19.5523 17 19 17H14.8284L12 19.8284L9.17154 17H5C4.44772 17 4 16.5523 4 16V6Z"></path></svg></span></span><span class="cdc-suspend-pill__item-number">0</span></button><button class="cdc-icon-btn cdc-suspend-pill__item collect cdc-icon-btn--text" qct-area="收藏文章" qct-click=""><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.2057 3.11487C10.9393 1.62838 13.059 1.62838 13.7927 3.11487L15.9724 7.53141L20.8463 8.23963C22.4867 8.478 23.1418 10.4939 21.9547 11.651L18.4279 15.0888L19.2605 19.9431C19.5407 21.5769 17.8258 22.8228 16.3586 22.0514L11.9992 19.7596L7.63981 22.0514C6.17255 22.8228 4.45769 21.5769 4.73791 19.9431L5.57048 15.0888L2.04366 11.651C0.856629 10.4939 1.51165 8.478 3.15209 8.23963L8.02603 7.53141L10.2057 3.11487ZM11.9992 4L9.8195 8.41654C9.52818 9.00683 8.96504 9.41597 8.31363 9.51062L3.43969 10.2188L6.9665 13.6566C7.43787 14.1161 7.65297 14.7781 7.5417 15.4269L6.70913 20.2812L11.0685 17.9893C11.6512 17.683 12.3472 17.683 12.9299 17.9893L17.2893 20.2812L16.4567 15.4269C16.3454 14.7781 16.5605 14.1161 17.0319 13.6566L20.5587 10.2188L15.6848 9.51062C15.0333 9.41597 14.4702 9.00683 14.1789 8.41654L11.9992 4Z"></path></svg></span></span><span class="cdc-suspend-pill__item-number">0</span></button><button class="cdc-icon-btn cdc-suspend-pill__item cdc-icon-btn--text"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path d="M13.0001 4V6H17.5859L10.1787 13.4072L11.6043 14.81L19.0001 7.41424V12H21.0001V4H13.0001Z"></path><path d="M3 12.9996C3 8.71646 5.99202 5.13211 10 4.22266V6.28952C7.10851 7.15007 5 9.82862 5 12.9996C5 16.8656 8.13401 19.9996 12 19.9996C15.1709 19.9996 17.8494 17.8912 18.71 14.9999H20.7769C19.8674 19.0077 16.2831 21.9996 12 21.9996C7.02944 21.9996 3 17.9702 3 12.9996Z"></path></svg></span></span></button><button class="cdc-icon-btn cdc-suspend-pill__item cdc-icon-btn--text"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M2 6C2 4.34315 3.34315 3 5 3H17C18.6569 3 20 4.34315 20 6V11H18V6C18 5.44772 17.5523 5 17 5H5C4.44772 5 4 5.44772 4 6V18C4 18.5523 4.44772 19 5 19H12V21H5C3.34315 21 2 19.6569 2 18V6ZM6 8H12V10H6V8ZM6 12H15V14H6V12ZM22 16H19V13H17V16H14V18H17V21H19V18H22V16Z"></path></svg></span></span></button><div class="cdc-suspend-pill__line"></div><button class="cdc-icon-btn cdc-suspend-pill__item cdc-icon-btn--text"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path d="M16.5047 6H13V4H20V10.876H18V7.33313L14.4571 10.876L13.0429 9.46182L16.5047 6Z"></path><path d="M11 6.00006H7.4953L10.9571 9.46189L9.54291 10.8761L6 7.33319V10.8761H4V4.00006H11V6.00006Z"></path><path d="M7.4953 18.8761H11V20.8761H4V14.0001H6V17.543L9.54291 14.0001L10.9571 15.4143L7.4953 18.8761Z"></path><path d="M16.5047 18.8761H13V20.8761H20V14.0001H18V17.543L14.4571 14.0001L13.0429 15.4143L16.5047 18.8761Z"></path></svg></span></span></button><button class="cdc-icon-btn cdc-suspend-pill__item recommend cdc-icon-btn--text" track-click="{&quot;areaId&quot;:106019,&quot;recPolicyId&quot;:1002,&quot;elementId&quot;:2}" track-exposure="{&quot;areaId&quot;:106019,&quot;recPolicyId&quot;:1002,&quot;elementId&quot;:2}"><span class="cdc-svg-icon-con"><span class="cdc-svg-icon" style="width:24px;height:24px"><svg width="24" height="24" viewBox="0 0 24 24" fill="currentcolor" xmlns="http://www.w3.org/2000/svg"><path d="M5 8H10V10H5V8Z"></path><path d="M10 12H5V14H10V12Z"></path><path d="M14 8H19V10H14V8Z"></path><path d="M19 12H14V14H19V12Z"></path><path fill-rule="evenodd" clip-rule="evenodd" d="M11 20.608L9.57047 20.1996C8.83303 19.9889 8.05701 19.9506 7.30243 20.0878L4.35777 20.6232C3.13009 20.8464 2 19.9033 2 18.6555V5.2669C2 4.2325 2.78877 3.36877 3.81893 3.27512L6.52892 3.02875C7.95704 2.89892 9.39058 3.21084 10.6356 3.9223L12 4.70194L13.3644 3.9223C14.6094 3.21084 16.043 2.89892 17.4711 3.02875L20.1811 3.27512C21.2112 3.36877 22 4.2325 22 5.2669V18.6555C22 19.9033 20.8699 20.8464 19.6422 20.6232L16.6976 20.0878C15.943 19.9506 15.167 19.9889 14.4295 20.1996L13 20.608L12.5 20.8535L12 20.8937L11.5 20.8535L11 20.608ZM6.70999 5.02054C7.73007 4.9278 8.75403 5.1506 9.64336 5.65879L11 6.43401V18.528L10.1199 18.2765C9.0875 17.9815 8.00107 17.928 6.94466 18.1201L4 18.6555V5.2669L6.70999 5.02054ZM13 18.528L13.8801 18.2765C14.9125 17.9815 15.9989 17.928 17.0553 18.1201L20 18.6555V5.2669L17.29 5.02054C16.2699 4.9278 15.246 5.1506 14.3566 5.65879L13 6.43401V18.528Z"></path></svg></span></span><span class="cdc-suspend-pill__item-text">推荐</span></button></div></div></div></div></div><script> if (!String.prototype.replaceAll) { String.prototype.replaceAll = function (str, newStr) { // If a regex pattern if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') { return this.replace(str, newStr); } // If a string return this.replace(new RegExp(str, 'g'), newStr); }; } </script><script src="https://developer.qcloudimg.com/static/jquery.min.js"></script><script src="https://cloud.tencent.com/qccomponent/login/api.js"></script><script src="https://cloudcache.tencent-cloud.com/qcloud/main/scripts/release/common/vendors/react/react.16.8.6.min.js"></script><script src="https://web.sdk.qcloud.com/player/tcplayer/release/v4.5.1/libs/TXLivePlayer-1.2.0.min.js" defer=""></script><script src="https://cloudcache.tencent-cloud.com/open/qcloud/video/tcplayer/libs/hls.min.0.13.2m.js"></script><script src="https://cloudcache.tencent-cloud.com/open/qcloud/video/tcplayer/tcplayer.v4.1.min.js"></script><script id="__NEXT_DATA__" type="application/json">{"props":{"isMobile":false,"isSupportWebp":false,"currentDomain":"cloud.tencent.com","baseUrl":"https://cloud.tencent.com","reqId":"u7kZj6jcQpTeb1nI3ve9O","query":{"articleId":"2465765"},"platform":"other","env":"production","__N_SSP":true,"pageProps":{"fallback":{"#url:\"/api/article/detail\",params:#articleId:2465765,,":{"articleData":{"articleId":2465765,"codeLineNum":11,"readingTime":453,"wordsNum":2076},"articleInfo":{"articleId":2465765,"channel":2,"commentNum":0,"content":{"blocks":[{"key":"21s4q","text":"重定向的实质","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5trr8","text":"\ud83d","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":0}],"data":{}},{"key":"149f3","text":"1和2的区别","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"16faa","text":"\ud83d","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":1}],"data":{}},{"key":"78l3k","text":"\ud83d","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"length":1,"key":2}],"data":{}},{"key":"48gn0","text":"在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"d8bm0","text":"文件描述符的含义","type":"header-four","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E7%9A%84%E5%90%AB%E4%B9%89"}},{"key":"4so","text":" 标准输入(stdin)\n ","type":"ordered-list-item","depth":0,"inlineStyleRanges":[{"offset":1,"length":4,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"1jcnl","text":"描述符: 0","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":4,"style":"BOLD"},{"offset":5,"length":1,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"euetj","text":"用途: 接收输入数据,通常是来自键盘的用户输入。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":3,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"5q3f","text":"使用场景: 例如,当你在命令行中运行程序时,可以通过键盘输入数据,这些数据会被程序读取。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":5,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"5rgjf","text":" 标准输出(stdout)\n ","type":"ordered-list-item","depth":0,"inlineStyleRanges":[{"offset":1,"length":4,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"5n40p","text":"描述符: 1","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":4,"style":"BOLD"},{"offset":5,"length":1,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"tskc","text":"用途: 用于输出数据,通常是显示在终端上的信息。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":3,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"2531o","text":"使用场景: 例如,echo \"Hello, World!\" 会将字符串输出到标准输出,即命令行界面。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":5,"style":"BOLD"},{"offset":9,"length":20,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"1ph","text":" 标准错误(stderr)\n ","type":"ordered-list-item","depth":0,"inlineStyleRanges":[{"offset":1,"length":4,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"av5li","text":"描述符: 2","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":4,"style":"BOLD"},{"offset":5,"length":1,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"6d517","text":"用途: 用于输出错误信息,通常也会显示在终端上,但可以与标准输出分开重定向。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":3,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"32irp","text":"使用场景: 例如,运行一个不存在的命令会产生错误信息,这些信息会输出到标准错误。","type":"unordered-list-item","depth":1,"inlineStyleRanges":[{"offset":0,"length":5,"style":"BOLD"}],"entityRanges":[],"data":{}},{"key":"1hhon","text":"使用示例","type":"header-four","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B"}},{"key":"amnrn","text":"以下是一些文件描述符的常见使用示例:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"8ko4j","text":"1. 基本输出","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"1.-%E5%9F%BA%E6%9C%AC%E8%BE%93%E5%87%BA"}},{"key":"3ltvv","text":"bash","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"dofu","text":"# 将字符串输出到标准输出\necho \"This is standard output\"","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"3873i","text":"2. 错误输出","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"2.-%E9%94%99%E8%AF%AF%E8%BE%93%E5%87%BA"}},{"key":"9mrcq","text":"bash","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"87scl","text":"# 使用不正确的命令产生错误信息\nsome_nonexistent_command","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"7v3v2","text":"3. 重定向标准输出","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"3.-%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA"}},{"key":"gmn6","text":"将标准输出重定向到文件:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"9jr0d","text":"bash","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5c1ms","text":"# 将输出重定向到文件 output.txt\necho \"This will be saved to a file\" \u003e output.txt","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"1t38c","text":"4. 重定向标准错误","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"4.-%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF"}},{"key":"7c81s","text":"将标准错误重定向到文件:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5j0dq","text":"bash","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"6dlrh","text":"# 将输出重定向到文件 output.txt\necho \"This will be saved to a file\" \u003e output.txt","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"7cj4u","text":"5. 同时重定向标准输出和标准错误","type":"header-five","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"5.-%E5%90%8C%E6%97%B6%E9%87%8D%E5%AE%9A%E5%90%91%E6%A0%87%E5%87%86%E8%BE%93%E5%87%BA%E5%92%8C%E6%A0%87%E5%87%86%E9%94%99%E8%AF%AF"}},{"key":"8el71","text":"将标准输出和标准错误同时重定向到同一个文件:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"98t4u","text":"bash","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"558vc","text":"# 将标准输出和标准错误都重定向到 same_output_and_error.txt\necho \"This will go to the file\" \u003e same_output_and_error.txt 2\u003e\u00261","type":"code-block","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"syntax":"javascript"}},{"key":"f9c85","text":"相关系统调用","type":"header-four","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E7%9B%B8%E5%85%B3%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8"}},{"key":"5tiv","text":"在编程中,你还可以使用系统调用来操作文件描述符,以下是一些常用的:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"4mqi1","text":"open(): 打开文件并返回文件描述符。","type":"unordered-list-item","depth":0,"inlineStyleRanges":[{"offset":0,"length":6,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"8jv62","text":"read(): 从文件描述符中读取数据。","type":"unordered-list-item","depth":0,"inlineStyleRanges":[{"offset":0,"length":6,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"dj22s","text":"write(): 向文件描述符写入数据。","type":"unordered-list-item","depth":0,"inlineStyleRanges":[{"offset":0,"length":7,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"e0drj","text":"close(): 关闭文件描述符。","type":"unordered-list-item","depth":0,"inlineStyleRanges":[{"offset":0,"length":7,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"efa80","text":"小结","type":"header-four","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E5%B0%8F%E7%BB%93"}},{"key":"e0rvo","text":"文件描述符 0、1 和 2 用于表示标准输入、标准输出和标准错误,它们在 Linux 等类 Unix 系统中是处理输入输出的基础。通过合理地使用它们,可以方便地进行 I/O 操作和错误处理。","type":"unstyled","depth":0,"inlineStyleRanges":[{"offset":6,"length":1,"style":"CODE"},{"offset":8,"length":1,"style":"CODE"},{"offset":12,"length":1,"style":"CODE"}],"entityRanges":[],"data":{}},{"key":"fgcg1","text":"文件描述符总结","type":"header-two","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E6%80%BB%E7%BB%93"}},{"key":"50p67","text":"Linux中的文件描述符总结如下:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"cebm9","text":"定义与用途:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5r11p","text":"文件描述符是内核为了高效管理已被打开的文件所创建的索引,是一个非负整数。\n 它用于代指被打开的文件,所有通过I/O操作的系统调用都通过文件描述符进行。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"1hqt2","text":"分配规则:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"fe1m","text":"当进程启动时,默认会打开三个文件描述符:标准输入(stdin,文件描述符为0)、标准输出(stdout,文件描述符为1)、标准错误(stderr,文件描述符为2)。\n 之后打开的文件,文件描述符会从3开始依次递增,为连续的整数。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"9hr1c","text":"限制:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"3pg9e","text":"系统级限制:限制所有用户打开文件描述符的总和,可以通过sysctl命令或查看proc文件系统来查询和修改。\n 用户级限制:限制每个用户登录后执行的程序占用的文件描述符总数,可以通过ulimit命令查询和修改。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"c9po7","text":"重定向:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"3vop7","text":"文件描述符支持重定向操作,包括输出重定向、输入重定向和追加重定向。\n 重定向允许用户将标准输入、输出或错误重定向到文件或其他设备。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"bqo2c","text":"与文件对象的关系:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"40dec","text":"用户在访问文件时,系统会将文件相关信息从磁盘中加载到内存,并在内核中创建文件对象。\n 文件描述符用于快速定位到这些文件对象,每个文件描述符都对应一个打开文件的文件对象。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"2huaq","text":"缓冲区:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"1k40n","text":"每个被打开的文件都各自拥有一个缓冲区。\n 使用write系统调用写入数据时,数据首先被拷贝到目标文件的缓冲区中,再由操作系统决定何时将数据刷新到外设中。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"b2r0j","text":"一切皆文件:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"5l41k","text":"在Linux下,一切皆文件,包括硬件设备、网络连接等,都可以通过文件描述符进行访问和操作。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"82eig","text":"综上所述,文件描述符是Linux内核中用于管理打开文件的一种机制,它提供了高效的文件访问方式,并支持重定向等高级功能。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"3r56b","text":"中文件描述符的具体作用是什么","type":"header-two","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E4%B8%AD%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E7%9A%84%E5%85%B7%E4%BD%93%E4%BD%9C%E7%94%A8%E6%98%AF%E4%BB%80%E4%B9%88"}},{"key":"102iu","text":"Linux中文件描述符的具体作用主要体现在以下几个方面:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"7rfdn","text":"唯一标识打开的文件或资源:文件描述符是一个非负整数,由操作系统内核分配,用于唯一标识一个已经打开的文件或输入输出资源(如管道、网络连接等)。这使得进程能够准确地访问和操作特定的文件或资源。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"9glf1","text":"支持多种I/O操作:文件描述符是进程与外部世界之间的桥梁。通过文件描述符,进程可以进行文件的读写操作、网络通信、进程间通信等。例如,使用read、write等系统调用进行文件内容的读取和写入,或者使用socket进行网络通信。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"4csu6","text":"实现重定向:文件描述符支持重定向操作,允许用户将标准输入、标准输出或标准错误重定向到文件或其他设备。这种灵活性使得程序能够更灵活地处理输入输出数据。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"je12","text":"管理打开的文件:每个进程都有一个文件描述符表,用于记录该进程打开的所有资源。文件描述符表对文件描述符进行管理,确保每个文件描述符都对应一个有效的打开文件或资源。同时,文件描述符的数量也是有限的,这有助于操作系统有效地管理资源。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"7s810","text":"综上所述,Linux中的文件描述符是一种高效、灵活的资源管理机制,它使得进程能够方便地访问和操作各种文件和资源。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"gulf","text":"如何理解“文件描述符”","type":"header-two","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{"text":"%E5%A6%82%E4%BD%95%E7%90%86%E8%A7%A3%E2%80%9C%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%E2%80%9D"}},{"key":"a8ail","text":"文件描述符是:","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"94vu8","text":"一个非负整数,由操作系统内核分配。\n 用于标识和访问已经打开的文件或I/O资源(如管道、网络连接)。\n 通过文件描述符,进程可执行文件的读写操作、网络通信等。\n 文件描述符支持重定向,允许灵活处理输入输出数据。","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}],"entityMap":{"0":{"type":"IMAGE","mutability":"IMMUTABLE","data":{"imageUrl":"https://developer.qcloudimg.com/http-save/yehe-11276311/d59c92d55316e9990d723371aea0cb60.png","imageAlt":"","name":"","blockWidth":736,"blockHeight":417}},"1":{"type":"IMAGE","mutability":"IMMUTABLE","data":{"imageUrl":"https://developer.qcloudimg.com/http-save/yehe-11276311/c5ea139d7d79fa2c18d189372f4c9014.png","imageAlt":"","name":"","blockWidth":720,"blockHeight":348}},"2":{"type":"IMAGE","mutability":"IMMUTABLE","data":{"imageUrl":"https://developer.qcloudimg.com/http-save/yehe-11276311/033cc2100ef7e724bfa18fa28e3f530c.png","imageAlt":"","name":"","blockWidth":1431,"blockHeight":1768}}}},"createTime":1731630712,"ext":{"closeTextLink":0,"comment_ban":0,"description":"","focusRead":0},"favNum":0,"isOriginal":0,"likeNum":1,"pic":"https://developer.qcloudimg.com/http-save/yehe-11276311/d59c92d55316e9990d723371aea0cb60.png","plain":"重定向的实质\n1和2的区别\n在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:\n文件描述符的含义\n 标准输入(stdin)\n \n描述符: 0\n用途: 接收输入数据,通常是来自键盘的用户输入。\n使用场景: 例如,当你在命令行中运行程序时,可以通过键盘输入数据,这些数据会被程序读取。\n 标准输出(stdout)\n \n描述符: 1\n用途: 用于输出数据,通常是显示在终端上的信息。\n使用场景: 例如,echo \"Hello, World!\" 会将字符串输出到标准输出,即命令行界面。\n 标准错误(stderr)\n \n描述符: 2\n用途: 用于输出错误信息,通常也会显示在终端上,但可以与标准输出分开重定向。\n使用场景: 例如,运行一个不存在的命令会产生错误信息,这些信息会输出到标准错误。\n使用示例\n以下是一些文件描述符的常见使用示例:\n1. 基本输出\nbash\n# 将字符串输出到标准输出\necho \"This is standard output\"\n2. 错误输出\nbash\n# 使用不正确的命令产生错误信息\nsome_nonexistent_command\n3. 重定向标准输出\n将标准输出重定向到文件:\nbash\n# 将输出重定向到文件 output.txt\necho \"This will be saved to a file\" \u003e output.txt\n4. 重定向标准错误\n将标准错误重定向到文件:\nbash\n# 将输出重定向到文件 output.txt\necho \"This will be saved to a file\" \u003e output.txt\n5. 同时重定向标准输出和标准错误\n将标准输出和标准错误同时重定向到同一个文件:\nbash\n# 将标准输出和标准错误都重定向到 same_output_and_error.txt\necho \"This will go to the file\" \u003e same_output_and_error.txt 2\u003e\u00261\n相关系统调用\n在编程中,你还可以使用系统调用来操作文件描述符,以下是一些常用的:\nopen(): 打开文件并返回文件描述符。\nread(): 从文件描述符中读取数据。\nwrite(): 向文件描述符写入数据。\nclose(): 关闭文件描述符。\n小结\n文件描述符 0、1 和 2 用于表示标准输入、标准输出和标准错误,它们在 Linux 等类 Unix 系统中是处理输入输出的基础。通过合理地使用它们,可以方便地进行 I/O 操作和错误处理。\n文件描述符总结\nLinux中的文件描述符总结如下:\n定义与用途:\n文件描述符是内核为了高效管理已被打开的文件所创建的索引,是一个非负整数。\n 它用于代指被打开的文件,所有通过I/O操作的系统调用都通过文件描述符进行。\n分配规则:\n当进程启动时,默认会打开三个文件描述符:标准输入(stdin,文件描述符为0)、标准输出(stdout,文件描述符为1)、标准错误(stderr,文件描述符为2)。\n 之后打开的文件,文件描述符会从3开始依次递增,为连续的整数。\n限制:\n系统级限制:限制所有用户打开文件描述符的总和,可以通过sysctl命令或查看proc文件系统来查询和修改。\n 用户级限制:限制每个用户登录后执行的程序占用的文件描述符总数,可以通过ulimit命令查询和修改。\n重定向:\n文件描述符支持重定向操作,包括输出重定向、输入重定向和追加重定向。\n 重定向允许用户将标准输入、输出或错误重定向到文件或其他设备。\n与文件对象的关系:\n用户在访问文件时,系统会将文件相关信息从磁盘中加载到内存,并在内核中创建文件对象。\n 文件描述符用于快速定位到这些文件对象,每个文件描述符都对应一个打开文件的文件对象。\n缓冲区:\n每个被打开的文件都各自拥有一个缓冲区。\n 使用write系统调用写入数据时,数据首先被拷贝到目标文件的缓冲区中,再由操作系统决定何时将数据刷新到外设中。\n一切皆文件:\n在Linux下,一切皆文件,包括硬件设备、网络连接等,都可以通过文件描述符进行访问和操作。\n综上所述,文件描述符是Linux内核中用于管理打开文件的一种机制,它提供了高效的文件访问方式,并支持重定向等高级功能。\n中文件描述符的具体作用是什么\nLinux中文件描述符的具体作用主要体现在以下几个方面:\n唯一标识打开的文件或资源:文件描述符是一个非负整数,由操作系统内核分配,用于唯一标识一个已经打开的文件或输入输出资源(如管道、网络连接等)。这使得进程能够准确地访问和操作特定的文件或资源。\n支持多种I/O操作:文件描述符是进程与外部世界之间的桥梁。通过文件描述符,进程可以进行文件的读写操作、网络通信、进程间通信等。例如,使用read、write等系统调用进行文件内容的读取和写入,或者使用socket进行网络通信。\n实现重定向:文件描述符支持重定向操作,允许用户将标准输入、标准输出或标准错误重定向到文件或其他设备。这种灵活性使得程序能够更灵活地处理输入输出数据。\n管理打开的文件:每个进程都有一个文件描述符表,用于记录该进程打开的所有资源。文件描述符表对文件描述符进行管理,确保每个文件描述符都对应一个有效的打开文件或资源。同时,文件描述符的数量也是有限的,这有助于操作系统有效地管理资源。\n综上所述,Linux中的文件描述符是一种高效、灵活的资源管理机制,它使得进程能够方便地访问和操作各种文件和资源。\n如何理解“文件描述符”\n文件描述符是:\n一个非负整数,由操作系统内核分配。\n 用于标识和访问已经打开的文件或I/O资源(如管道、网络连接)。\n 通过文件描述符,进程可执行文件的读写操作、网络通信等。\n 文件描述符支持重定向,允许灵活处理输入输出数据。","showReadNum":79,"sourceDetail":null,"sourceType":99,"status":2,"summary":"在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:","tagIds":[17506,17591,16250,17332,17440],"title":"文件描述符fd和0 \u0026 1 \u0026 2的含义(stdin..)","uid":11276311,"updateTime":1731630712,"userSummary":"在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:","userUpdateTime":1731630712},"authorInfo":{"articleNum":0,"avatarUrl":"https://developer.qcloudimg.com/avatar/26311.png","company":"","introduce":"","isProfessionVerified":0,"nickname":"ljw695","privilege":1,"title":"","uid":11276311},"authorType":{"isBlogMoveAuthor":1,"isCoCreator":0,"isInternalAuthor":0,"isOriginalAuthor":0},"classify":[{"id":20,"name":"操作系统"}],"columnInfo":{"columnAvatar":"https://cloudcache.tencent-cloud.com/qcloud/developer/images/release/column-icons/8.png","columnDesc":"","columnId":103967,"columnName":"ljw","createTime":1729053491,"createUid":11276311,"memberNum":1,"showArticleNum":83,"showConcernNum":13},"columnList":[{"columnAvatar":"https://cloudcache.tencent-cloud.com/qcloud/developer/images/release/column-icons/8.png","columnDesc":"","columnId":103967,"columnName":"ljw","createTime":1729053491,"createUid":11276311,"memberNum":1,"showArticleNum":83,"showConcernNum":13}],"editTime":0,"isTencent":false,"longtailTags":[],"publishTime":1731630712,"sourceDetail":{"blogType":2,"blogUrl":"https://blog.csdn.net/2401_83427936?spm=1011.2415.3001.5343","channelSource":"csdn","originalTime":"2024-11-05","sourceAuthor":"","sourceLink":"https://blog.csdn.net/2401_83427936/article/details/142466919","wechatNickName":"","wechatUserName":""},"tags":[{"categoryId":99,"createTime":"2023-03-14T11:34:59+08:00","groupId":0,"groupName":"","tagId":17506,"tagName":"系统"},{"categoryId":99,"createTime":"2023-03-14T11:35:00+08:00","groupId":0,"groupName":"","tagId":17591,"tagName":"重定向"},{"categoryId":99,"createTime":"2023-03-14T11:34:37+08:00","groupId":0,"groupName":"","tagId":16250,"tagName":"stdin"},{"categoryId":99,"createTime":"2023-03-14T11:34:56+08:00","groupId":0,"groupName":"","tagId":17332,"tagName":"进程"},{"categoryId":99,"createTime":"2023-03-14T11:34:58+08:00","groupId":0,"groupName":"","tagId":17440,"tagName":"数据"}],"textLink":[{"ext":{"categoryId":1026,"categoryName":"通用技术 - 操作系统","desc":"文件系统是一种用来组织和管理计算机存储设备(如硬盘、闪存、光盘等)上文件和目录的结构的软件。它负责在存储设备上分配空间、记录文件位置、保存文件属性和权限等信息,以及提供对文件和目录的读、写、复制、删除等操作。","kpCount":12,"name":"文件系统","pCategoryId":1002,"termId":1993},"id":3690,"link":"https://cloud.tencent.com/developer/techpedia/1993","sources":[2],"text":"文件系统"},{"ext":{"categoryId":1026,"categoryName":"通用技术 - 操作系统","desc":"Linux是一种开源的操作系统,它由Linus Torvalds在1991年创建。它基于Unix操作系统,具有高度的稳定性、安全性和可靠性。Linux操作系统可以在各种计算机硬件上运行,包括个人电脑、服务器、移动设备和嵌入式系统。","kpCount":16,"name":"Linux","pCategoryId":1002,"termId":1821},"id":3530,"link":"https://cloud.tencent.com/developer/techpedia/1821","sources":[2],"text":"Linux"},{"ext":{"categoryId":1026,"categoryName":"通用技术 - 操作系统","desc":"Unix是一种多用户、多任务、支持多种处理器架构的操作系统。它最初由AT\u0026T贝尔实验室开发,于1969年首次发布。Unix操作系统为用户提供了许多强大的工具和命令行界面,使得用户可以进行高级的系统管理和编程工作。","kpCount":12,"name":"Unix","pCategoryId":1002,"termId":1960},"id":3657,"link":"https://cloud.tencent.com/developer/techpedia/1960","sources":[2],"text":"Unix"}]},"#url:\"/api/tag/products\",params:#tagIds:@17506,17591,16250,17332,17440,,objectType:1,objectId:2465765,,":[]},"tdk":{"title":"文件描述符fd和0 \u0026 1 \u0026 2的含义(stdin..)-腾讯云开发者社区-腾讯云","keywords":"系统,重定向,stdin,进程,数据","description":"在 Linux 系统中,文件描述符(File Descriptor, FD)是一个非负整数,用于标识打开的文件、输入/输出设备或其他资源。标准输入、标准输出和标准错误是最常用的文件描述符,其对应的值为 0、1 和 2,具体含义和使用说明如下:"},"meta":{"subject":"其他-空类-系统,其他-空类-重定向,其他-空类-stdin,其他-空类-进程,其他-空类-数据","subjectTime":"2024-11-15 08:31:52","articleSource":"B","magicSource":"N","authorType":"Z","productSlug":"none"},"link":{"canonical":"https://cloud.tencent.com/developer/article/2465765"},"cssName":["Article","DraftMaster","Player"],"rbConfigKeys":["groupQRKeywords"],"pvId":"u7kZj6jcQpTeb1nI3ve9O","clientIp":"8.222.208.146","globalAnnounce":{"announceId":29,"content":"发文进行双十一晒单,聊省钱攻略,开箱云产品,最高赢万元奖励。点击查看活动详情:\u003ca href=\"https://cloud.tencent.com/developer/article/2462518\" target=\"_blank\"\u003ehttps://cloud.tencent.com/developer/article/2462518\u003c/a\u003e\u003cbr/\u003e \n \u003cimg src=\"https://qcloudimg.tencent-cloud.cn/raw/9f72dee064adec96fefa6f314527b6fe.jpg\"/\u003e","title":" 摇人!全网寻技术圈双十一课代表!"},"rbConfig":{"groupQRKeywords":{"AI":{"keywords":[],"img":"https://qcloudimg.tencent-cloud.cn/raw/89b22f53dc3d4e0516d0a4f74ab01a30.png"}},"versionUpdateTipList":"","navList":[{"text":"学习","menuList":[{"iconName":"article","title":"文章","desc":"技术干货聚集地","href":"/developer/column?from=19154"},{"iconName":"ask","title":"问答","desc":"技术问题讨论区","href":"/developer/ask?from=19155"},{"iconName":"video","title":"视频","desc":"技术视频记录区","href":"/developer/video?from=19156"},{"iconName":"learn","title":"学习中心","desc":"一站式学习平台","href":"/developer/learning"},{"iconName":"lab","title":"腾讯云实验室","desc":"体验腾讯云产品功能","href":"/lab/labslist?from=20154\u0026from_column=20154\u0026channel=c1004\u0026sceneCode=dev"}]},{"text":"活动","menuList":[{"iconName":"living","title":"直播","desc":"技术大咖面对面","href":"/developer/salon?from=19161"},{"iconName":"competition","title":"竞赛","desc":"秀出你的技术影响力","href":"/developer/competition?from=19162"}]},{"text":"专区","menuList":[{"iconName":"code","title":"CODING DevOps专区","desc":"云原生开发技术实践交流","href":"/developer/zone/codingdevops?from=19163"},{"iconName":"cloudstudio","title":"Cloud Studio专区","desc":"云端IDE开发者平台","href":"/developer/zone/cloudstudio?from=19165"},{"iconName":"cloudnative","title":"腾讯云原生专区","desc":"助力业务降本增效","href":"/developer/zone/cloudnative?from=19164"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/ipass.svg","title":"腾讯轻联专区 ","desc":"新一代应用与数据集成平台","href":"/developer/zone/ipaas"},{"iconName":"https://qcloudimg.tencent-cloud.cn/raw/1deae15bfe2dcdd1036f601852df7dd2.svg","title":"腾讯云数据库专区","desc":"数据智能管理专家","href":"/developer/zone/tencentdb"},{"iconName":"https://qcloudimg.tencent-cloud.cn/raw/cb0703ff9de6b664413f4ed7d31a9224.svg","title":"腾讯云大数据专区","desc":"打造专业、易用、可信赖的大数据产品","href":"/developer/zone/bigdata"},{"iconName":"https://qcloudimg.tencent-cloud.cn/raw/1d60f881ef280ea992e2e4b6490d974b.svg","title":"腾讯云TCE专区","desc":"私有化云解决方案","href":"/developer/zone/tce"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/cos.svg","title":"腾讯云存储专区","desc":"安全稳定的海量分布式存储服务","href":"/developer/zone/cos"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/andon.svg","title":"腾讯云安灯专区","desc":"助力企业构建IT服务管理体系","href":"/developer/zone/tcandon"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/sale.svg","title":"腾讯云运维技术沙龙","desc":"聚焦运维技术与云上治理","href":"/developer/zone/tcdevopssalon"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/audio.svg","title":"腾讯云音视频","desc":"提供坚实的数字化助力","href":"/developer/zone/mediaservices"},{"iconName":"https://qccommunity.qcloudimg.com/icons/tencentcloudsmartadvisor.svg","title":"腾讯云顾问","desc":"实现便捷、灵活的一站式云上治理","href":"https://cloud.tencent.com/developer/zone/tencentcloudsmartadvisor"},{"iconName":"https://qccommunity.qcloudimg.com/icons/tencenthunyuan.svg","title":"腾讯混元","desc":"具备强大的中文创作、逻辑推理、任务执行能力","href":"https://cloud.tencent.com/developer/zone/tencenthunyuan"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/ai.svg","title":"腾讯云智能","desc":"数实融合,云上智能","href":"https://cloud.tencent.com/developer/zone/ai"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/Dnspod.svg","title":"dnspod","desc":"专业的智能DNS解析和域名托管服","href":"https://cloud.tencent.com/developer/zone/dnspod"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/lighthouse.svg","title":"轻量应用服务器","desc":"新一代开箱即用、面向轻量应用场景的云服务器","href":"https://cloud.tencent.com/developer/zone/lighthouse"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/HAi.svg","title":"高性能应用服务","desc":"提供即插即用的高性能云服务","href":"https://cloud.tencent.com/developer/zone/hai"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/blockchain.svg","title":"腾讯云区块链","desc":"云链聚未来,协同无边界","href":"https://cloud.tencent.com/developer/zone/tencentcouldbockchain"},{"iconName":"https://qccommunity.qcloudimg.com/community/image/OpencloudOS.svg","title":"OpenCloudOS","desc":"开源中立的国产操作系统社区","href":"https://cloud.tencent.com/developer/zone/opencloudos"},{"iconName":"https://cloudcache.tencent-cloud.com/qcloud/ui/static/static_source_business/b3e1b483-be77-4e08-827f-ef0e5cda26cf.svg","title":"边缘安全加速平台EO","desc":"下一代CDN—EdgeOne,不止加速","href":"https://cloud.tencent.com/developer/zone/tencentcloudedgeone"}]},{"text":"工具","menuList":[{"iconName":"https://qccommunity.qcloudimg.com/icons/ai-assistant.svg","title":"腾讯云AI代码助手","desc":"辅助编码工具,使研发提效增质","href":"https://cloud.tencent.com/product/acc?from=22178"},{"iconName":"coding","title":"CODING DevOps","desc":"一站式软件研发管理平台","href":"/product/coding?from=20154\u0026from_column=20154"},{"iconName":"studio","title":"Cloud Studio","desc":"随时随地在线协作开发","href":"/product/cloudstudio?from=20154\u0026from_column=20154"},{"iconName":"sdk","title":"SDK中心","desc":"开发者语言与SDK","href":"/document/sdk?from=20154\u0026from_column=20154"},{"iconName":"api","title":"API中心","desc":"API 助力快捷使用云产品","href":"/document/api?from=20154\u0026from_column=20154"},{"iconName":"tool","title":"命令行工具","desc":"可快速调用管理云资源","href":"/document/product/440/6176?from=20154\u0026from_column=20154"}]}],"activity-popup":{"mImgUrl":"https://qccommunity.qcloudimg.com/mp/images/11-11mobile.jpg","imgUrl":"https://qccommunity.qcloudimg.com/mp/images/11-11pc.jpg","beginTime":"2024/10/24 00:00:00","endTime":"2024/10/31 23:59:59"},"header-advertisement":{"imageUrl":"https://qccommunity.qcloudimg.com/image/2024-11-01-18-15.png","link":"https://cloud.tencent.com/act/pro/double11-2024?from=22374\u0026from_column=22374#miaosha"}},"isBot":false,"session":{"isLogined":false,"isQCloudLogined":false,"isQCommunityLogined":false,"isDifferentUin":false}}},"page":"/article/[articleId]","query":{"articleId":"2465765"},"buildId":"A33mNyh0oM2Hz_SodWz7T","assetPrefix":"https://qccommunity.qcloudimg.com/community","isFallback":false,"gssp":true,"appGip":true,"scriptLoader":[]}</script></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10