From owner-freebsd-net Wed Oct 11 14:31:11 2000 Delivered-To: freebsd-net@freebsd.org Received: from center.mshindo.net (center.mshindo.net [210.231.221.221]) by hub.freebsd.org (Postfix) with ESMTP id CBC2437B503 for ; Wed, 11 Oct 2000 14:31:01 -0700 (PDT) Received: from cosinecom.com (proxy53.cosinecom.com [63.88.104.53]) by center.mshindo.net (8.9.3/3.7W/00041811) with SMTP id GAA10364 for ; Thu, 12 Oct 2000 06:38:01 +0900 (JST) Date: Thu, 12 Oct 2000 06:30:16 +0900 (JST) Message-Id: <20001012.063016.112630716.mshindo@mshindo.net> To: freebsd-net@freebsd.org Subject: pty question From: Motonori Shindo X-Mailer: Mew version 1.95b30 on XEmacs 21.1 (Canyonlands) X-PGP-fingerprint: 06 B0 B1 A4 06 C1 6A 14 63 C0 D7 18 01 CD D9 83 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Hi, I'm trying to use pty but it doesn't work as I expect. I probably miss something, but I can't find it for the last few days... Here's the essence of my program. It's supposed to work in a way that a child (slave) process reads data from starndard input, which is actually connected to a parent process (master)'s file discriptor 'fdm_w'. However, the slave doesn't seem to read anything from the standard input, though master did write somehting to the corresponding file descriptor. On the other hand, the opposite direction works, i.e, if slave writes something, master can read it OK. You may wonder why two pairs of ptys, but it's a differnt stroy I guess (uun, maybe not..). This is done because if master writes data but subsequent read by master reads the same thing it has written before (i.e loopbaked), so I decided to use two ptys, one for read and another for write. Any advise will be greatly appreciated! Best Regards, #include #include #include #include #include #include #include int main() { int fdm_r, fdm_w; int fds_r, fds_w; char buf[256]; int p; int x; openpty(&fdm_r, &fds_w, NULL, NULL, NULL); openpty(&fdm_w, &fds_r, NULL, NULL, NULL); bzero(buf, sizeof(buf)); p = fork(); if (p == 0) { /* child */ close(0); close(1); /* close(2); */ close(fdm_r); close(fdm_w); fprintf(stderr, "debug\n"); if (dup2(fds_r, 0) == -1) { fprintf(stderr, "dup2\n"); exit(1); } if (dup2(fds_w, 1) == -1) { fprintf(stderr, "dup2\n"); exit(2); } fprintf(stderr, "slave reading\n"); x = read(0, buf, 3); fprintf(stderr, "slave %d read\n", x); if (buf[0] == 'A') { printf("BBB\n"); } else { printf("ZZZ\n"); } exit(1); } else { /* parent */ close(fds_r); close(fds_w); printf("master writing\n"); sleep(3); write(fdm_w, "AAAAA", 5); printf("master written\n"); printf("master reading\n"); read(fdm_r, buf, 5); printf("%c%c%c\n", buf[0], buf[1], buf[2]); } return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message