Article View: comp.unix
Article #326PIPES
From: Arvind Krishnan
Date: Wed, 21 Nov 1990 00:05
Date: Wed, 21 Nov 1990 00:05
63 lines
1963 bytes
1963 bytes
two pipes for full duplex communications with its child (mailx).
1. stdout of the child is the stdin of the parent and
2. stdout of the parent is the stdin of the child
For some unknown reason, '1' works but '2' doesn't. The parent process can
read the output of its child, but the child doesn't seem to be reading the
output of the parent process.
Can someone please figure out whats happening and let me know!
The code fragment at fault is as follows.
Thanks a lot in advance. Any help will be greatly appreciated.
Arvind
-------------------------------------------------------------------------------
char command[] = "1";
int start_mail()
{
int to_par[2], to_child[2];
char buf[8];
int flag = 0;
if (pipe(to_par))
return -1;
if (pipe(to_child))
return -1;
if (fork() == 0)
{
close(0);
dup2(to_child[0], 0);
close(1);
dup2(to_par[1], 1);
close(to_par[1]);
close(to_child[0]);
close(to_par[0]);
close(to_child[1]);
if (execl("/usr/bin/mailx", "mailx", (char *) 0))
fprintf(stderr,"Exec Error\n");
}
close(1);
dup2(to_child[1], 1);
close(0);
dup2(to_par[0], 0);
close(to_child[1]);
close(to_par[0]);
close(to_child[0]);
close(to_par[1]);
fcntl(0, F_SETFL, O_NDELAY);
while (1)
{
if (flag == 0)
while ((flag = read(0,buf,1)) == 0);
write(2,buf,1);
flag = read(0,buf,1);
if (flag == 0)
write(1, command, 1);
}
}
Technical Details
Message-ID:
<2274@megadon.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!olivea!apple!altos!megadon!clpShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!olivea!apple!altos!megadon!clp From: akrishn@csserv2.ic.sunysb.edu (Arvind Krishnan) Newsgroups: comp.unix Subject: PIPES Message-ID: <2274@megadon.UUCP> Date: 21 Nov 90 00:05:46 GMT Sender: clp@megadon.UUCP Followup-To: akrishn@csserv2.ic.sunysb.edu Organization: State University of New York at Stony Brook Lines: 63 Approved: clp@megadon.UUCP Originator: akrishn@csserv2