Thread View: ru.qa.network
1 messages
1 total messages
Started by Simon Yeh
Thu, 03 Nov 1988 23:48
Re: How to do a pipe & fork?
Author: Simon Yeh
Date: Thu, 03 Nov 1988 23:48
Date: Thu, 03 Nov 1988 23:48
55 lines
2124 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads