Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> pipe trouble, after child dies pipe goes crazy!!
sid
Posted: Feb 25 2005, 02:46 AM
Quote Post


Newbie
*

Group: Members
Posts: 1
Member No.: 834
Joined: 25-February 05



i am having trouble in a program where i am using select command to monitor the pipe end in the parent .the pipe is used for the child to write nad the parent to read only .the read and write neds in the child and parent respectively , are closed .
now when the child dies , the parent end of the pipe becomes readable with 0 characters and i cannot read that and so apparantly (if pipes are buffered) the buffer does not clear and it remains readable thus making the select go into an infinite loop of continuously reading the pipe .
if anybody knows whats causing this please help me out .also if anybody knwos how to clear a pipe buffer that might also help fix the problem .
the code snippet is
if ( (pid= Fork() ) == 0) // FORKING CHILD PROCESS
{
close(pfd[0]); //CLOSE READ IN CHLD
dup2(pfd[1], 3); // DUPLICATE WRITE SOCKET
if (pfd[1]!= 3) close(pfd[1]); //CLOSE EXTRA SOCKET
switch(choice){
case 1: {execlp("xterm", "xterm", "-e", "./tcpcli01", str, (char *) 0);break;}
case 2: {execlp("xterm", "xterm", "-e", "./tcpcli02", str, (char *) 0);break;}
}
}
else { // inside parent
close (pfd[1]); //CLOSE WRITE AT PARENT
FD_ZERO(&rset);
FD_SET(pfd[0], &rset);
FD_SET(0, &rset);
maxfdp1 = max(pfd[0],0) + 1 ;
for( ; ; ){
allset = rset;
if( (n=select(maxfdp1, &allset, NULL, NULL, NULL)) <=0 ){// SELECT
if(errno==EINTR) {
close(pfd[0]);break;
}
else { printf("SELECT ERROR (NOT EINTR)\n");break;}
}

if (FD_ISSET(pfd[0], &allset)) { /* socket readable */
n2 = read(pfd[0], buf, MAXLINE);
if (n2 == 0)
FD_CLR(pfd[0], &rset);
else
write(1,buf,n2);
}

if (FD_ISSET(0, &allset)) { /* input is readable */
printf("write in the exec window please!!\n");
read(0,buf,MAXLINE);
}

}
PMEmail Poster
Top
fishsponge
Posted: Feb 27 2005, 12:43 AM
Quote Post


Administrator
********

Group: Admin
Posts: 679
Member No.: 1
Joined: 13-February 03



topic moved to the Programming/Languages forum.
PMEmail PosterUsers WebsiteICQAOLYahooMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Programming/Languages | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.3433 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: Server Room Temperature Monitor :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum