04-01-2013
Re:
Since I'm having so much trouble comprehending how piping works in C, and since the professor said we were free to make our own version of the code from scratch, I decided to abandon the pipe/fork/dup2 approach and instead just use popen, after finding an example of that on the 'Net, and that did the trick. But thanks for the help. Hopefully come test time, I will better understand how dup2 and all that works.
9 More Discussions You Might Find Interesting
1. Solaris
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
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
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
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
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
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
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
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
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
DUP(2) BSD System Calls Manual DUP(2)
NAME
dup, dup2 -- duplicate an existing file descriptor
SYNOPSIS
#include <unistd.h>
int
dup(int fildes);
int
dup2(int fildes, int fildes2);
DESCRIPTION
dup() duplicates an existing object descriptor and returns its value to the calling process (fildes2 = dup(fildes)). The argument fildes is
a small non-negative integer index in the per-process descriptor table. The value must be less than the size of the table, which is returned
by getdtablesize(2). The new descriptor returned by the call is the lowest numbered descriptor currently not in use by the process.
The object referenced by the descriptor does not distinguish between fildes and fildes2 in any way. Thus if fildes2 and fildes are duplicate
references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non-blocking I/O
and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference
to the file must be obtained by issuing an additional open(2) call. The close-on-exec flag on the new file descriptor is unset.
In dup2(), the value of the new descriptor fildes2 is specified. If fildes and fildes2 are equal, then dup2() just returns fildes2; no other
changes are made to the existing descriptor. Otherwise, if descriptor fildes2 is already in use, it is first deallocated as if a close(2)
call had been done first.
RETURN VALUES
Upon successful completion, the new file descriptor is returned. Otherwise, a value of -1 is returned and the global integer variable errno
is set to indicate the error.
ERRORS
The dup() and dup2() system calls will fail if:
[EBADF] fildes is not an active, valid file descriptor.
[EINTR] Execution is interrupted by a signal.
[EMFILE] Too many file descriptors are active.
The dup2() system call will fail if:
[EBADF] fildes2 is negative or greater than the maximum allowable number (see getdtablesize(2)).
SEE ALSO
accept(2), close(2), fcntl(2), getdtablesize(2), open(2), pipe(2), socket(2), socketpair(2)
STANDARDS
dup() and dup2() are expected to conform to IEEE Std 1003.1-1988 (``POSIX.1'').
4th Berkeley Distribution December 1, 2010 4th Berkeley Distribution