- 论坛徽章:
- 0
|
我的程序在全国各地的20多台小型机上都跑了快一年了,各种UNIX版本都有,最近也是第一次碰到这种情况。
我的父子程序同步是用管道方式,会不会是收到SIGPIPE信号了?代码如下:
- if (pipe(fd) < 0) {
- ADD_ERR_LOG(funcname, "creating pipe failed",
- strerror(errno));
- return;
- }
- ch = '\0';
- pid = fork();
- if (pid < 0) {
- ADD_ERR_LOG(funcname, "fork failed", strerror(errno));
- return;
- } else if (pid == 0) { /** son */
- /**@ waiting for father to record status */
- close(fd[1]);
- if (read(fd[0], &ch, 1) != 1) {
- close(fd[0]);
- ADD_ERR_LOG(funcname, "reading from pipe failed",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
- close(fd[0]);
- ....
- exit(EXIT_SUCCEED);
- }
- ....
- close(fd[0]);
- if (write(fd[1], &ch, 1) != 1) {
- ADD_ERR_LOG(funcname, "writing to pipe failed",
- strerror(errno));
- }
- close(fd[1]);
复制代码 |
|