首页 \ 问答 \ stdin,stdout和stderr之间是否共享?(stdin, stdout and stderr are shared between?)

stdin,stdout和stderr之间是否共享?(stdin, stdout and stderr are shared between?)

我试图了解三个流的行为 - stdoutstdinstderr 。 我无法从任何教科书中得到答案,所以我来到这里。

我知道这三个存储在文件描述符表中,文件描述符为0(stdin),1(stdout)和2(stderr)。 我也知道这些不仅仅是文件描述符,而是可以重定向的I / O流。 好的,分享怎么样?

考虑三种情况:

  1. 调用fork()时 :子进程和父进程共享文件描述符,但它们是否具有相同的stdin,stdout和stderr?
  2. 创建线程时:线程共享文件描述符,但是I / O流?
  3. 调用execl()时 :在这种情况下,当前过程映像将被新过程映像覆盖。 如果我执行execl("./a.out", "a.out", NULL); 那么这个新的可执行文件是否会获得stdin,stderr和stdout的全新副本?

欢迎所有明智的答案。


I am trying to understand the behavior of the three streams - stdout, stdin and stderr. I couldn't get the answer from any textbook, so I came here.

I know that these three are stored in file descriptor table with file descriptors 0 (stdin), 1 (stdout) and 2 (stderr). I am also aware that these are not merely file descriptors but I/O streams which can be redirected. Ok, so how about sharing?

Consider the three cases:

  1. When a fork() is called : The child process and parent process shares file descriptors, but do they have the same stdin, stdout and stderr ?
  2. When a thread is created : Threads share file descriptors, but I/O streams?
  3. When execl() is called : In this case the present process image is overwritten with new process image. If I do execl("./a.out", "a.out", NULL); , then will this new executable get a freshcopy of stdin, stderr and stdout?

All wise answers are welcome.


原文:https://stackoverflow.com/questions/26687602
更新时间:2023-07-20 18:07

最满意答案

请参阅此错误报告 ,特别是密切注释:

这不是一个错误。 理论上,“$ value”可能不是1,2或3,在这种情况下,switch() 不会因其中一个值离开。 Xdebug不能对“doSomething()”返回的内容做出假设,无法知道所有返回的内容都不是1,2或3.每个函数和方法的最后一个包含一个隐式的“返回NULL”; - 哪个PHP看作可执行代码。 因为存在未命中}的可能代码路径,所以它被标记为“未执行”。

在你的情况下,你有三个案例陈述,我想你已经为它们编写了测试,但是你可能会或可能不会测试第三个隐含的路径 - 如果这三个案例都不匹配怎么办?

tl; dr:为交换机添加一个default大小写,并确保你的测试运用它。 或者不要忽略该覆盖线。


See this bug report, specifially the close note:

This is not a bug. In theory "$value" could be something else than 1, 2 or 3 and in that case the switch() would not leave due to one of the values. Xdebug can not make assumptions on what "doSomething()" returns an has no way to know that all that ever is returned than 1, 2 or 3. The last } of each function and method includes an implicit "return NULL;" - which PHP sees as executable code. Because there is a possible code path where the } is not hit, it is marked as "not executed".

In your case, you have three case statements, that I imagine you've written tests for, but there's a third, implied path that you may or may not be testing for - what to do if none of the three cases match?

tl;dr: Add a default case to the switch, and make sure your tests exercise it. Or don't and ignore that coverage line.

相关问答

更多
  • 首先:100%的代码覆盖率是一个很好的指标。 这并不总是可以实现的,而且这样做并不总是很重要的:) 问题来自xDebug,告诉PHPUnit这一行是可执行的,但没有涉及。 对于简单的情况,xDebug可以告诉该行不可访问,因此您可以在那里获得100%的代码覆盖率。 看下面的简单例子 。 第二次更新 该问题现在修复了xDebug bugtracker因此构建新版本的xDebug将解决这些问题:) 更新(请参阅下面的有关php 5.3.x的问题) 由于您正在运行PHP 5.4和xDebug的DEV版本,我已经安 ...
  • 请注意,这应该是一个评论,并没有回答不直接回答问题。 它质疑问题的有用性。 退出使用emma并开始使用jacoco 。 自2007年左右以来,艾玛一直处于休眠状态。艾玛中心的最新版艾玛插件是从2010年开始的。 截至今日(2013年第一季度)。 从feb-2013 到maven中心有一个版本 。 org.jacoco jacoco 0.6.2.20130 ...
  • 尝试这个: ASPX <%@page codepage="65001" language="C#" lcid="6153"%> <%@ Import namespace="YourProgram.YourNamespace" %> <% public class MyAuthenticator:IAuthenticator{ public Task AuthenticateAsync(ICommandRequest commandRequest,CancellationToken ca ...
  • 实际上我也在我的项目中有这个,但我取消选中/取消选择VSCode底部的流覆盖选项。 这将在代码中的流错误和未覆盖的代码之间切换。 未覆盖的代码是外部代码(导入的模块),有时是您自己的,更可能是第三方依赖项(如本例所示),它们不定义流类型。 因此,流程无法检查类型的一致性。 您可以按照注释中的建议从flow-typed安装react-redux类型定义。 实际上我过去曾尝试过这种情况并导致整个世界的痛苦,所以我离开了它。 作为旁注,请考虑这一点......旨在100%类型检查覆盖范围与100%测试覆盖率(谷歌 ...
  • 请参阅此错误报告 ,特别是密切注释: 这不是一个错误。 理论上,“$ value”可能不是1,2或3,在这种情况下,switch() 不会因其中一个值而离开。 Xdebug不能对“doSomething()”返回的内容做出假设,无法知道所有返回的内容都不是1,2或3.每个函数和方法的最后一个包含一个隐式的“返回NULL”; - 哪个PHP看作可执行代码。 因为存在未命中}的可能代码路径,所以它被标记为“未执行”。 在你的情况下,你有三个案例陈述,我想你已经为它们编写了测试,但是你可能会或可能不会测试第三个隐 ...
  • 所以我终于找到了答案,VS格式化选项没有生效的原因是因为ReSharper的格式化选项优先。 该设置位于Resharper - >编辑器 - >编辑器行为“关闭括号上的自动格式”“分号自动格式化”“自动插入右括号” So I finally found the answer, the reason why VS formatting options did not take effect was because the formatting options from ReSharper took prece ...
  • 好吧,我现在正坐在角落里,戴上我的帽子。 发现这个: https : //github.com/istanbuljs/nyc/issues/35#issuecomment-121008298 未覆盖线= 17不是未覆盖线的计数,而是仅有一个值的列表,即第17行: total: total || 1, total: total || 1, ,。 修正... test('passing zero forces the default total of 1', () => { const bar = prog ...
  • 几年前我做过这样的事情。 这是很久以前的事了,我不确定我会以同样的方式做它(它没有真正扩展到双重限制等)你如何输出它可能是一个不同的问题。 我使用了2002 - 2003年的表格。 今天肯定有更好的技术。 锦标赛中的回合数量为log2(玩家)+ 1,只要玩家是您在上面指定的数字之一。 使用此信息,您可以计算出有多少回合。 最后一轮包含最终的赢家。 我存储了这样的播放器信息(调整此内容以获得最佳实践) Tournament Name Size Players Tournament Name ...
  • 在简单的语句中,两者在Java编程的上下文中是相同的。 我假设method()的返回类型是boolean 。 Java中不允许使用if (method() === false) 。 这是一个编译时错误。 不要在JavaScript语法和Java语法之间混淆。 JSP在内部转换为在服务器上执行的Servlet,并将生成的HTML响应发送回客户端(浏览器)。 所以它根本没有转换为JavaScript 。 In simple statement both are same in the context of Ja ...
  • if [ $(grep -E -f slew_pattern /etc/sysconfig/ntpd) ]; then 对于多个匹配,此命令肯定会失败。 当grep输出在行结束时被分割时,它将抛出一个错误。 grep多个匹配由新行分隔,测试命令变为: [ match1 match2 match3 ... ] 这没有多大意义。 您将获得与grep返回的匹配数不同的错误消息(即test command [的参数数量)。 例如: 2匹配将给你unary operator expected错误 3匹配将给你bi ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)