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) 							System Calls Manual							   PIPE(2)

NAME
pipe - create an interprocess channel SYNOPSIS
#include <u.h> #include <libc.h> int pipe(int fd[2]) DESCRIPTION
Pipe creates a buffered channel for interprocess I/O communication. Two file descriptors are returned in fd. Data written to fd[1] is available for reading from fd[0] and data written to fd[0] is available for reading from fd[1]. After the pipe has been established, cooperating processes created by subsequent fork(2) calls may pass data through the pipe with read and write calls. The bytes placed on a pipe by one write are contiguous even if many processes are writing. Write boundaries are preserved: each read terminates when the read buffer is full or after reading the last byte of a write, whichever comes first. The number of bytes available to a read(2) is reported in the Length field returned by fstat or dirfstat on a pipe (see stat(2)). When all the data has been read from a pipe and the writer has closed the pipe or exited, read(2) will return 0 bytes. Writes to a pipe with no reader will generate a note sys: write on closed pipe. SOURCE
/sys/src/libc/9syscall SEE ALSO
intro(2), read(2), pipe(3) DIAGNOSTICS
Sets errstr. BUGS
If a read or a write of a pipe is interrupted, some unknown number of bytes may have been transferred. When a read from a pipe returns 0 bytes, it usually means end of file but is indistinguishable from reading the result of an explicit write of zero bytes. PIPE(2)
All times are GMT -4. The time now is 12:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy