Sponsored Content
Homework and Emergencies Homework & Coursework Questions Cannot correctly connect multi-stage C command pipe (among others) (FYI: a lot of code) Post 302787955 by kowit010 on Sunday 31st of March 2013 02:12:59 PM
Old 03-31-2013
Re:

Yeah, I know, sorry the code is so huge, I guess I had to post the whole code so the mods don't come down on me for not filling out the whole thread template, but anyway... I wish I had time to simplify the code, now I'm just trying to get this thing going. I changed the code to this (just including the problem area in the "create_command_process" function):

Code:
if(childpid=fork())//if more than one process, and this is the parent process....
 {
  if((cmd_pids[i]=(int)childpid)==-1)//did it fork correctly?
  {
   perror("Error forking!");
   exit(666);
  }
  close(prev[0]);//close previous filedescriptor in
  close(prev[1]);//close previous filedescriptor out
  close(curr[0]);
  close(curr[1]);
 }
 else
 {
  if(prev[1]!=-1)//if previous pipe has a valid item
  {
      dup2(prev[0],0);
      dup2(prev[1],1);
      close(prev[0]);
      close(prev[1]);
  }
  if(curr[0]!=-1)//if current pipe has a valid item
  {
      dup2(curr[0],0);
      dup2(curr[1],1);
      close(curr[0]);
      close(curr[1]);
  }
    execvp(test,argvector);//execute the process....
 }

When I run it with "ls | wc", absolute NO output to the shell console comes back (even though it's writing stuff to my logfile). I will work on this some more, but I don't know if this means it's working now? Aren't I like supposed to get a set of numbers back for "ls | wc"? (running it in shell spits out "16 16 150" in my current folder). Then again, the assignment description says this, and I quote:

" 
The standard output stream is used and used only for printing command execution results.
"

So I take this to mean I shouldn't have to worry enough about it printing anything straight to the console?


---------- Post updated at 01:12 PM ---------- Previous update was at 01:11 PM ----------

Quote:
Originally Posted by Corona688
Also, exit(666) makes no sense. It only takes numbers 1-127.
Oh, really? I didn't know that. I just heard that any non-zero number fed into an exit() call indicated failure so I use 666 to be a wise guy for obvious reasons, bahahaha. I'll change it, though, to be something in that valid range. Thanks.
 

9 More Discussions You Might Find Interesting

1. Solaris

Solaris has a lot of bugs, fstream wont write to file correctly!

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)
Discussion started by: Joncamp
4 Replies

2. Shell Programming and Scripting

How to get exit code in a pipe-lined command?

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)
Discussion started by: pankai
3 Replies

3. Shell Programming and Scripting

find command takes a lot of time ( can I skip directories)

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)
Discussion started by: knijjar
3 Replies

4. UNIX for Dummies Questions & Answers

Date command to obtain the last month is not working correctly..

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)
Discussion started by: tigersk
9 Replies

5. UNIX for Advanced & Expert Users

command taking lot of time to execute

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)
Discussion started by: john_prince
3 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Why code run not correctly

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)
Discussion started by: FUTURE_EINSTEIN
4 Replies

7. Solaris

Can I run repair on lot of blocks with single command ?

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)
Discussion started by: solaris_1977
1 Replies

8. UNIX for Beginners Questions & Answers

How to compile a Datastage Job using Execute Command Stage or Routines in Datastage 11?

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)
Discussion started by: elena jessi
1 Replies

9. Shell Programming and Scripting

Egrep -v command not filtering correctly

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)
Discussion started by: evergreen
3 Replies
PIPE(2) 						      BSD System Calls Manual							   PIPE(2)

NAME
pipe -- create descriptor pair for interprocess communication SYNOPSIS
#include <unistd.h> int pipe(int *fildes); DESCRIPTION
The pipe() function creates a pipe, which is an object allowing unidirectional data flow, and allocates a pair of file descriptors. The first descriptor connects to the read end of the pipe, and the second connects to the write end, so that data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one program to be sent to another program: the source's standard output is set up to be the write end of the pipe, and the sink's standard input is set up to be the read end of the pipe. The pipe itself persists until all its associated descriptors are closed. A pipe whose read or write end has been closed is considered widowed. Writing on such a pipe causes the writing process to receive a SIGPIPE signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count. RETURN VALUES
On successful creation of the pipe, zero is returned. Otherwise, a value of -1 is returned and the variable errno set to indicate the error. ERRORS
The pipe() call will fail if: [EMFILE] Too many descriptors are active. [ENFILE] The system file table is full. [EFAULT] The fildes buffer is in an invalid area of the process's address space. SEE ALSO
sh(1), read(2), write(2), fork(2), socketpair(2) HISTORY
A pipe() function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution
All times are GMT -4. The time now is 10:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy