🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: ru.qa.network
Article #1

Re: How to do a pipe & fork?

#1
From: Simon Yeh
Date: Thu, 03 Nov 1988 23:48
55 lines
2124 bytes
In article <Nov.2.14.51.36.1988.8260@zztop.rutgers.edu>, pratt@zztop.rutgers.edu (Lorien Y. Pratt) writes:
>OK, an even easier question than I posted last time, I'd really appreciate
>your help.
>Here's what I have so far, which I know is wrong.

You may try this....[Note: lines starting with /*@*/ are what I added]

 #include <netdb.h>
 #include <stdio.h>
 #define STRLEN 40
 
 main()
 {
 int pid;
 char from_sql[256];
 char *fgets();
 int i;
 /*@*/ int fd[2]; /* store file descriptors for pipe */
 
 /*@*/ pipe(fd);  /* creat pipe */
 
 pid = fork();
 
 if (pid == 0)   /* We are the children */
 {
   /*@*/ dup2(fd[1], 1); /* redirect child's stdout to fd[1] 
                            so child can talk to parent */
   /*@*/ close(df[0]); close(fd[1]);
   /* This part works.  I tested it in its own program without being a child. */
   i = execlp("rsh", "rsh", "topaz", "/u2/ingres/bin/sql", "spam", 0);
   printf("execlp didn't work, return code is %d\n", i);
   /*@*/ exit(1);
 }
 else
 {
   printf( "Child's process ID is %d\n", pid ); fflush(stdout);
   /*@*/ close(fd[1]);
 
   /* Start talking to child */
   /*@*/ fgets(from_sql, 256, fd[0] ); /* read what child says from fd[0] */
   printf("SQL says: %s\n", from_sql );
 
   /*@*/ fclose( fd[0] );
   ......
 }
 .....
}

>Lorien Y. Pratt                            Computer Science Department
>pratt@paul.rutgers.edu                     Rutgers University

Hope this will help.

--- Simon Yeh
Technical Details
Message-ID: <Nov.3.18.48.07.1988.1780@caip.rutgers.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utgpu!attcan!uunet!husc6!rutgers!caip.rutgers.edu!syeh
References: <Nov.2.14.51.36.1988.8260@zztop.rutgers.edu>

Show Full Headers
Complete Article Headers
Message-ID: <Nov.3.18.48.07.1988.1780@caip.rutgers.edu>
Subject: Re: How to do a pipe & fork?
Date: Thu, 03 Nov 1988 23:48:08 +0000
From: syeh@caip.rutgers.edu (Simon Yeh)
References: <Nov.2.14.51.36.1988.8260@zztop.rutgers.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utgpu!attcan!uunet!husc6!rutgers!caip.rutgers.edu!syeh
Newsgroups: comp.unix.wizards,ru.qa.network
Organization: Rutgers Univ., New Brunswick, N.J.
Lines: 54