The brief program below is designed to iterate over argv passed from the command line and execute each argument. This is not my homework, but rather what I do, preparing for my homework.
The first argument is entered from STDIN and STDOUT and written to the channel. At the end of each iteration (except the last), the file descriptors are swapped so that the channel recorded by the last exec will be read next. Thus, I suppose, for example, for
./a.out /bin/pwd /usr/bin/wc
to print only the length of the working directory. The code follows
#include <stdio.h>
UPDATE : in all of the test cases below, which I originally used / bin / wc, but which wc showed that the water cabinet was not at all where I was thinking. I am in the process of amending the results.
The output in the trivial case (./a.out/bin/pwd) looks as expected:
1: /bin/pwd Received string: /home/zeigfreid/Works/programmatical/Langara/spring_2012/OS/labs/lab02/play
The result of starting this program with the first example (./a.out/bin/pwd/usr/bin/wc):
1: /bin/pwd 0 1 3 4 3 4 0 1 2: /bin/wc
At this point, the terminal freezes (maybe waiting at the entrance).
As you can see, the line is not accepted. I suppose that I did something wrong above, either when replacing the pointers, or that I do not understand the unix file descriptors. Ultimately, my task will be to interpret arbitrarily long pipes, and this is one of the ideas that I had to solve the problem. I have problems evaluating whether I am on the right track barking in a tree. Do I understand unix file descriptors?
UPDATE:
Running it with / bin / ls as the second argument, I got the following result (numbers are file descriptors at different points):
1: /bin/pwd 0 1 3 4 0 1 3 4 3 4 0 1 2: /bin/ls 3 4 5 6 Received string: a.out log pipe2.c play.c @
There is still trash in the end, but now it bothers me more that I don't understand the pointers! The two teams are independent of each other, although in reality they do not use the pipe.
UPDATE : garbage symbol was not closed. Now I close it and not trash.