linux下读取管道 总是返回1
C/C++ code:
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int pipe_fd[2];
pid_t pid;
char buf_r[100];
char* p_wbuf;
ssize_t r_num;
memset(buf_r,0,sizeof(buf_r));
if ( pipe(pipe_fd)< 0 )
{
printf("pipe create error\n");
return -1;
}
if ( (pid = fork())==0 )
{
printf(" i'm in child process\n");
close(pipe_fd[1]);
sleep (2);
if( (r_num = read(pipe_fd[0],buf_r,100)>0) ){
printf("%u numbers read from the pipe is %s\n",r_num,buf_r);
}
close(pipe_fd[0]);
exit(0);
}
else if(pid > 0){
printf("i'm in parent process\n");
close(pipe_fd[0]);
if( (write(pipe_fd[1],"hello",5)!=-1) ){
printf("parent write1 success\n");
}
if( (write(pipe_fd[1]," pipe",5)!=-1) ){
printf("parent write2 success\n");
}
close(pipe_fd[1]);
//sleep(3);
waitpid(pid,NULL,0); /*wait for pid process done*/
exit(0);
}
return 0;
}
为什么总是返回1?谢谢啦
if( ((
相关问答:
有人认为,linux 安全性高,只是因为用的人少,所以那些黑客不愿意去攻击,所以病毒之类的就少,是不是这样?而且linux是开源的,攻击起来 比较容易所以 懒的去攻击
这种说法对么
linux 怎么就安全高 ......
我用过ubuntu8.10版本,从verycd下载的。
下载后,是半英文。且我对linux系统的操作理解不深,因此装中文输入法都搞了好久。
然后按照网上的教程更新中文界面,但是更新了1晚上后提示中断……雷。
......
小弟最近需要一个用socket获取html文档的代码,但是老是不能获取完整的html源码。原因不明,望高手指点!
C/C++ code:
char *Http_GET(char *host,int port,char *data) //发送GET请求
{
char response[2 ......
原先的GCC版本为4.1.2,我重新编译安装了GCC4.3.2,但是编译完程序运行程序时会出现version `GLIBCXX_3.4.9' not found 这个问题.在网上面查了一下是软连接的问题。但是本人对Linux不太熟悉,“应该制作RPM包然后 ......