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
dup2(3C) Standard C Library Functions dup2(3C)
NAME
dup2 - duplicate an open file descriptor
SYNOPSIS
#include <unistd.h>
int dup2(int fildes, int fildes2);
DESCRIPTION
The dup2() function causes the file descriptor fildes2 to refer to the same file as fildes. The fildes argument is a file descriptor refer-
ring to an open file, and fildes2 is a non-negative integer less than the current value for the maximum number of open file descriptors
allowed the calling process. See getrlimit(2). If fildes2 already refers to an open file, not fildes, it is closed first. If fildes2
refers to fildes, or if fildes is not a valid open file descriptor, fildes2 will not be closed first.
The dup2() function is equivalent to fcntl(fildes, F_DUP2FD, fildes2).
RETURN VALUES
Upon successful completion a non-negative integer representing the file descriptor is returned. Otherwise, -1 is returned and errno is set
to indicate the error.
ERRORS
The dup2() function will fail if:
EBADF The fildes argument is not a valid open file descriptor.
EBADF The files2 argument is negative or is not less than the current resource limit returned by getrlimit(RLIMIT_NOFILE, ...).
EINTR A signal was caught during the dup2() call.
EMFILE The process has too many open files. See fcntl(2).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |Async-Signal-Safe |
+-----------------------------+-----------------------------+
SEE ALSO
close(2), creat(2), exec(2), fcntl(2), getrlimit(2), open(2), pipe(2), lockf(3C), attributes(5), standards(5)
SunOS 5.10 19 Dec 2003 dup2(3C)