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:

 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); }}   

By the way, how can other processes get input? Scanf?

I think your pipe is set correctly Problems 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.

The next problem is that sort is text based, and more specifically line-based, and you are sending binary scraps to your STDIN.

In the original process you should write formatted text in the pipe.

  FILE * wpipe = fdopen (FD [1], "W"); {Fprintf (wpipe, "% d \ n", i) for (I = 100; i & lt; 110; i ++); ...} fclose (wpipe);   

The reverse loop can do a little better testing of your sorting from 110 to 100.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -