Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
We are supposed to write a C program that parses a command line, separates it into each command (further separates each command into its argument vectors), and then creates a multi-stage execution pipeline.
Example: "ls -l | grep ^d | wc -l"
The program must also print the results to a LOGFILE of each command created, the PIDs of each command, and the exit status of all commands. Finally, the program needs to wait for each program to execute, kill each command if Cntl-C is hit while the pipeline is executing and start over, or simply end the program if Cntl-C is hit beforehand.
2. Relevant commands, code, scripts, algorithms:
This is the code we have to work with. I apologize for the super-long massive block of code, and any problems with formatting or displaying this properly here, but this is what we must work with, and believe me, no one is more frustrated trying to comprehend this than me, since I am not very good at C programming:
file: piper.c
3. The attempts at a solution (include all code and scripts):
I ran the command "ls | grep ^d | wc -l" in the shell, and then ran it again in my program and these are the results from both (first shell, then program):
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
(when I posted this thread, I could not access the website, but that's definitely it)
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
I have heard an expert C programmer call this "one pig of an assignment." Because I have not been able to get the piping working correctly, I have not had time to see if my Cntl-C, wait() calls, or logfile printing works correctly, and this is due tonight at midnight. Hopefully someone is on here given how today is Easter (when most of us should be with our families anyway), but a lot of this code was given to us from the TAs, and even then it didn't work (I had to edit some places here just to get it running).
I have been working on this for three weeks and cannot figure out what is happening, so I am very desperate here. I have also had problems on other boards because users who are a lot more knowledgeable with C programming than I am are a little too snide and harsh with me, someone who is already as nervous as a newbie usually is, and also has deep emotional problems that make it hard to interact with the public because of being on the receiving end of overzealous or even downright arrogant remarks that easily can get taken as attacks (even if the person who said it wasn't intending it). I am not looking for trouble, but please... go easy on me, okay?
Any help here would be greatly appreciated! Thank you and Happy Easter! (if you celebrate it, that is, otherwise.. Happy Chocolate Day, I guess??)
P.S. If it would help or if my post is incomprehensible, I can provide the assignment description upon request.
---------- Post updated at 10:44 AM ---------- Previous update was at 10:39 AM ----------
Sometimes when I run my own code, running something "ls | grep ^d | wc -l" would print the results of "ls" before printing the rest (what prints out is not uniform in its order), but if I do something like:
I've got a c++ program that works fine on Linux, compiles on Solaris fine with g++, but will not write to a fstream correctly in a class object.
And I've run into numerous other bugs in the disk management.
Jon (4 Replies)
I have a question about how to get the exit code of the first command when it appears in a pipe-lined command.
For example, I have the following script:
grep abc dddd | tee -a log
if ]
then
echo "ERROR!"
fi
In the above script, ] is supposed to test the exit code of "grep abc... (3 Replies)
I have a file called "library" with the following content
libnxrdbmgr.a
libnxrdbmgr.so
libnxtk.a
libnxtk.so
libora0d_nsc_osi.so
I am trying to locate if these libraries are on my machine or not. find command runs for about few seconds and hangs after this.
Can someone please help me and... (3 Replies)
Hello,
I could not find the exactly same post here.. so I will explain what I did to get the last month using date command.
I used
date +%Y-%m -d "-1 months"
to get the last month. However, the returned value of above command on 2009/10/31 was 2009 10 and not 2009 09.. and the... (9 Replies)
Hi,
I am running the following command, and it tries to delete some dn from ldap, however, it takes lot of time before it finally request LDAP server to delete it.
I am trying to find why it is taking lot of time. Could you anyone help me in this regard. I have copies the pstack output, and... (3 Replies)
Hi there can anyone help me
here is my code
echo "Type in a positive number"
read X
I=2
while
do
if
then
echo "It is not prime"
break
else
if
then
echo "It is prime"
break
else
I=$(( $I + 1))
fi
fi (4 Replies)
Hi,
I have Solaris-10 OS on T5220. Both local disks were mirrored under SVM. Somehow when one disk gone bad (c0t1d0), other disk (c0t0d0) also got lot of bad block. We have readable data only on c0t0d0, but as soon as server comes after, it hangs when I run few commands because of read errors,... (1 Reply)
I am trying to compile the datastage jobs using the Execute Command stage in datastage 11 or any Routines if possible. My datastage is on Unix machine.
So, How can I Compile a datastage job in UNIX from command line or any Routines.
Please help me in doing so.
Thank you. (1 Reply)
Hello guys,
I have an issue when trying to do an egrep -v on a file, let me show you.
I want to filter the last column as to where it filters out the columns with asterisks and zeros ( * and 0 ) it is working properly up to a certain point where I have a value of '10000' which is also getting... (3 Replies)