fork - put pipe to stdin another process -
I am using pipes to parse another process to array numbers. So far, I am able to get results from another process, although fdopen, I do not understand how to send data as a pipe to another process.
Here is my code: By the way, how can other processes get input? Scanf? I think your pipe is set correctly Problems The next problem is that In the original process you should write formatted text in the pipe. The reverse loop can do a little better testing of your sorting from 110 to 100.
int main () {int fd [2], i, val; Pid_t children; Four files [10]; FILE * f;
pipe (FD); Children = fork (); If (child == 0) {closed (FD [1]); Dupta 2 (FD [0], STDINIFLNO); Close (FD [0]); Execl ("sort", "sort", NULL); } And {off (FD [0]); Printf ("before \ n"); For (i = 100; i & lt; 110; i ++) {write (FD [1], & amp; i, size (int)); Printf ("% d \ n", i); } Closed (FD [1]); Wait (zero); }}
execl () For this call, you should specify a full path, which is probably
/ bin / sort if you have a UNIX utility call
execlp () There is also a version that automatically searches on the path.
sort is text based, and more specifically line-based, and you are sending binary scraps to your STDIN.
FILE * wpipe = fdopen (FD [1], "W"); {Fprintf (wpipe, "% d \ n", i) for (I = 100; i & lt; 110; i ++); ...} fclose (wpipe);
Comments
Post a Comment