|
已经用mkfifo定义一个文件“DataToGps” 管道
但是在以下的程序中,在打开DataToGps管道时阻塞,不知如何解决。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(){
FILE * Outfile;
char buf[20];
printf("open file!\n");
Outfile=fopen("DataToGps","w");
if(Outfile==NULL){
perror("Error in foprn!");
exit(1);
}
printf("file opened!\n");
pid_t fork1,fork2;
fork1=fork();
if(fork1<0){
printf("fork1 creat erro!\n");
}
else{
if(fork1!=0){
fork2=fork();
if(fork2<0){
printf("fork2 creat erro!\n");
}
else{
if(fork2==0){
printf("fork1 creat ok! ID:%d \n",getpid());
execl("./fork2","fork2",0);
perror("exec error");
}
else{
printf("fork ok! ID:%d \n",getpid());
fwrite("tEST DATA!",1,8,Outfile);
//write(DataToGps[OUTPUT],"test data!\n",strlen("test data!"));
}
}
}
else{
//close(DataToGps[OUTPUT]);
//read(DataToGps[INPUT],buf,20);
printf("fork1 creat ok! ID:%d \n",getpid());
execl("./fork1","fork1",0);
perror("exec error");
}
}
while(1){;}
} |
|