- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个家庭作业问题,我们必须编写一个带有两个参数的程序,将它们作为 shell 命令执行,将第一个程序的标准输出通过管道传输到第二个程序的标准输入。
这是我的solution对于这个家庭作业问题。下面复制了相同的文件。
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#define SHELL "/bin/sh"
extern int main(int, char*[]);
static int readingend(int, int, const char*);
static int writingend(int, int, const char*);
static int usr1handler();
extern int
main(int argc, char *argv[])
{
int pipefd[2], status;
pid_t rpid, wpid;
if (argc != 3) {
fprintf(stderr, "Invalid argument count\n");
return (EXIT_FAILURE);
}
if (pipe(pipefd)) {
perror("Cannot make a pipe");
return (EXIT_FAILURE);
}
signal(SIGUSR1, (void(*)(int))usr1handler);
if ((rpid = fork()) < 0) {
perror("Cannot fork");
return (EXIT_FAILURE);
}
if (rpid == 0)
return (readingend(pipefd[0], pipefd[1], argv[2]));
if ((wpid = fork()) < 0) {
perror("Cannot fork");
kill(rpid, SIGKILL);
return (EXIT_FAILURE);
}
if (wpid == 0)
return (writingend(pipefd[0], pipefd[1], argv[1]));
close(pipefd[0]);
close(pipefd[1]);
waitpid(rpid, &status, 0);
return (status);
}
static int
readingend(int rfd, int wfd, const char *cmd)
{
close(wfd);
dup2(rfd, STDIN_FILENO);
/* execl() only returns on error */
execl(SHELL, SHELL, "-c", cmd, NULL);
fprintf(stderr, "Cannot execute %s: ", cmd);
perror(NULL);
/* clean up */
kill(getppid(), SIGUSR1);
return (EXIT_FAILURE);
}
static int
writingend(int rfd, int wfd, const char *cmd)
{
close(rfd);
dup2(wfd, STDOUT_FILENO);
execl(SHELL, SHELL, "-c", cmd, NULL);
fprintf(stderr, "Cannot execute %s: ", cmd);
perror(NULL);
/* clean up */
kill(getppid(), SIGUSR1);
return (EXIT_FAILURE);
}
static int
usr1handler()
{
/* child already printed diagnostic */
exit(EXIT_FAILURE);
}
问题在于,在某些调用中,第一个进程在从 stdin 读取时收到 EIO
。这似乎只发生在某些 shell 上:它发生在 ksh93
和 bash
上,但不会发生在 bosh
上。这样的错误看起来像这样:
$ LANG=C ./mypipe cat true$ cat: -: Input/output error
谁能告诉我为什么会出现这个错误?我该怎么做才能不再出现该错误?显然,必须有一种方法可以执行 cat | true
在普通 shell 中会产生所需的结果,而不会产生任何虚假的 EIO
。
最佳答案
发生此问题的原因是 true
立即终止,导致 mypipe
也终止,从而使 cat
孤立。如果发生这种情况,read()
可能会失败:
EIO
The process is a member of a background process attempting to read from its controlling terminal, the process is ignoring or blocking the
SIGTTIN
signal, or the process group is orphaned. This error may also be generated for implementation-defined reasons.
可以通过等待两个进程来防止此问题,如下所示:
extern int
main(int argc, char *argv[])
{
int status, estatus;
/* ... */
/* wait for both processes to terminate */
if (wait(&status) == rpid) {
estatus = status;
wait(&status);
} else {
wait(&status);
estatus = status;
}
return (estatus);
}
关于c - pipeline()-ing 程序会导致 EIO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23983860/
我正在维护用户可以在其上部署 Web 应用程序的 Web 服务器软件。 Web 应用程序作为单独的进程运行:Web 服务器启动 Web 应用程序进程,将 HTTP 请求转发到 Web 应用程序,并将
另一个简单的例子: if (wpa_s->mlme.ssid_len == 0) return -EINVAL; 为什么是一元减号?这(通常)是针对成功时返回 >0 和失败时返回 = 0) {
我有一个使用 MongoDB 的 Express 应用程序。 我在开发时使用 Nodemon 重新启动我的进程。为了在我重新启动我的应用程序时关闭我的数据库连接,我调用: db.close() 关于以
我们有一个家庭作业问题,我们必须编写一个带有两个参数的程序,将它们作为 shell 命令执行,将第一个程序的标准输出通过管道传输到第二个程序的标准输入。 这是我的solution对于这个家庭作业问题。
我正在使用 node.js + socket.io + Winston(记录器)编写一个游戏服务器,我的服务器每天都因为这个异常而死机: Error: write EIO at errnoExcept
我使用 NFS 在我的系统上安装了远程磁盘,并且我正在尝试使用 pwrite() API 写入已安装的远程磁盘上的文件。 这种情况并非每次都会发生,但在某些情况下,在执行 I/O 时 pwrite()
我的应用程序基于 Socket.io,具有聊天功能。 我的应用程序部署在红帽开放类次上。 我不断收到http://url/socket.io/?EIO=3&transport=polling&t=Lj
我在 window7-32bit 上用 nodejs + mongodb + Backbone 制作了一个 webApp,直到昨天一切正常。但是今天早上我收到了这个错误: events.js:72
我正在调查 Android 上的一个问题,其中由于未能关闭文件而引发 IOException: java.io.IOException: close failed: EIO (I/O error)
我使用 Node js Express 和 socket.io 以及 apache 作为我的反向代理。以下是我的反向代理配置。 ProxyPass /chatApp http://localhost:
我在 Linux 上运行 NodeJs 服务器,几个小时后它崩溃了: events.js:72 throw er; // Unhandled 'error' event
如果 close(2) 系统调用因 EIO 而失败,文件描述符是否仍会被删除? 如果是,是否无法通过稍后重试来处理虚假 IO 错误?如果不是,应该如何防止文件描述符泄漏? 最佳答案 这是一个棘手的问题
我正在尝试使用forkpty来execvp一个ls/,然后从父进程读取它的输出并写入stdout . 我让它工作了,并且在 Valgrind 下运行它也没有显示任何错误。 编辑:Valgrind 没有
我正在使用 Angular 2 构建一个投资组合网站。我知道有更简单的方法来实现它,但这对我来说也是一种复习,因为我已经有一段时间没有使用 Angular 2 了。 当我尝试使用“ng serve”来
我在 ExpressJS 和 NodeJS 中的后端曾经运行良好。我刚刚意识到日志爆炸了磁盘(后端仍然可用),因为当后端打开时,它一直在尝试: kpi.js GET /socket.io/?EIO=3
wss://www.mysite.ca/socket.io/?EIO=3&transport=websocket 这是 chrome webdevoloper 工具显示套接字 io 的请求 url 的
close(2) 的 Linux 手册页指出: NOTES Not checking the return value of close() is a common but nevertheless
如果由 shell 执行,以下代码可以按预期运行。 但是如果我将此程序设置为用户的 shell 并通过 ssh 进入主机以将此程序作为 shell 执行,read(0, &buf123, 1); 将返
我在一个node.js站点上工作,该站点在端口8443和端口443上使用socket.io。该站点在本地工作,并对指向生产服务器的dns记录使用namecheap。我最近将名称服务器设置为Cloudf
我正在编写一些代码,它获取一个文件,将该文件传递给多个二进制文件之一进行处理,并监视转换过程中的错误。我已经在 OSX 上编写并测试了以下例程,但 linux 因我不清楚的原因而失败。 #run th
我是一名优秀的程序员,十分优秀!