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(2) System Calls Manual dup2(2)
NAME
dup2 - duplicate an open file descriptor to a specific slot
SYNOPSIS
DESCRIPTION
fildes is a file descriptor obtained from a or system call.
fildes2 is a non-negative integer less than the maximum value allowed for file descriptors.
causes fildes2 to refer to the same file as fildes. If fildes2 refers to an already open file, the open file is closed first.
The file descriptor returned by has the following in common with fildes:
o Same open file (or pipe).
o Same file pointer (that is, both file descriptors share one file pointer.)
o Same access mode (read, write or read/write).
o Same file status flags (see fcntl(2),
The new file descriptor is set to remain open across system calls. See fcntl(2).
This routine is found in the C library. Programs using but not using other routines from the Berkeley importability library (such as the
routines described in bsdproc(3C)) should not give the option to ld(1).
RETURN VALUE
Upon successful completion, returns the new file descriptor as a non-negative integer, fildes2. Otherwise, it returns -1 and sets to indi-
cate the error.
ERRORS
fails if the following is true:
fildes is not a valid open file descriptor or fildes2 is not in the range of legal file descriptors.
An attempt to close
fildes2 was interrupted by a signal. The file is still open.
WARNINGS
A multithreaded application or an application with a signal handler can exhibit a race between on one thread and another kernel call that
assigns a new file descriptor while running on a second thread or signal handler. If fildes2 is free before the call was made, the other
thread or signal handler may win the race and acquire that descriptor (e.g., in an call). The thread calling can then close this file and
reuse the descriptor. This results in multiple functions improperly referring to the same file.
This race can be avoided either by ensuring that fildes2 references an open file before calling or by providing user-level synchronization
(or signal disabling) which makes sure that the thread and another thread or signal handler don't make competing calls into the kernel at
the same time.
SEE ALSO
close(2), creat(2), dup(2), exec(2), fcntl(2), open(2), pipe(2), privileges(5).
STANDARDS CONFORMANCE
dup2(2)