08-10-2008
Quote:
Originally Posted by
fpmurphy
dup() duplicates an existing file descriptor (in this case fd=3) and returns
the new descriptor to the calling process. It does not close the existing
fiel descriptor.
The new descriptor returned by the call to dup() is the lowest numbered
descriptor currently not in use by the process (in this case fd=4)
Thanks for your answer.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi there,
I found the following script on the net, i like to use it as a standard template for new scripts.
But i do not understand the meaning of the last line, can anybody explain what going on on the last line
vflag=off
filename=
while getopts vf: opt
do
case "$opt" in
v)... (9 Replies)
Discussion started by: janr
9 Replies
2. Shell Programming and Scripting
Hi, i've got the following:
a=`echo $b | grep '^.*/'`
i'm storing in the variable the value of the variable b only if it has a / somewhere.
It works, but i don't want to print the value. How do i give the value of b to the grep command without the echo?
thanks! (5 Replies)
Discussion started by: kfad
5 Replies
3. Shell Programming and Scripting
Hello..
I am doing some awk-ing and among all I use substr inside it..
I have: ....substr($0,60,37)
meaning as U all know take from 37 char. from point 60..
can I put it like this substr($0,60,end of line)
meaning take it from point 60 and take all characketrs in that line until line... (2 Replies)
Discussion started by: amon
2 Replies
4. Shell Programming and Scripting
First af all hi.
i want to create a batch script which inform when users log in last time on system or if they are online when they logged in.
I want ot use a file .users which has the usernames of users.
i want to print for example
peter is ONLINE: Logged in on Wed Feb 11 07:47
alex... (2 Replies)
Discussion started by: sasa
2 Replies
5. UNIX for Dummies Questions & Answers
I am looking for some model like this:
My Computer
-------------
Intermediate Server (IS)
-------------
Own Server
I must be able to ssh into the Intermediate Internet Server which is generally an online version of SSH service through which I will connect to Own Server. I was the IS to... (2 Replies)
Discussion started by: Legend986
2 Replies
6. Shell Programming and Scripting
Hello All,
Im opening a file desciptor in perl and sending data using print CMD "$xyz".
is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
Discussion started by: rimser9
3 Replies
7. Programming
Hello experts,
I am using fork() in my code but I am confused which output comes first child or parent?
I did the following code .My book shows parent first but my linux shows child first.Can anyone tell me why?
#include <stdio.h>
int main(){
int pid;
printf("I am original process with pid... (5 Replies)
Discussion started by: mlhazan
5 Replies
8. Shell Programming and Scripting
just to confirm
du from sh show sizes as multiples of 512 byte right? (4 Replies)
Discussion started by: Nick1097
4 Replies
9. Programming
I have this small program that runs with the flat assembler. My problem is that at the receive line function it receives the line and if there isn't a $ typed at the end of the user input the program displays a lot of strange stuff, sometimes beeps and then it seems to terminate without causing any... (13 Replies)
Discussion started by: Errigour
13 Replies
10. Homework & Coursework Questions
For the command below, I need to understand what exactly the command does and provide an examples for which the output will be saved to file save2... From my understanding, if the file provides an error in the first half of the pipe, it'll save to save1 and will never give an error to save to... (2 Replies)
Discussion started by: ayz649
2 Replies
LEARN ABOUT OPENDARWIN
dup2
DUP(2) BSD System Calls Manual DUP(2)
NAME
dup, dup2 -- duplicate an existing file descriptor
SYNOPSIS
#include <unistd.h>
int
dup(int oldd);
int
dup2(int oldd, int newd);
DESCRIPTION
Dup() duplicates an existing object descriptor and returns its value to the calling process (newd = dup(oldd)). The argument oldd 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 oldd and newd in any way. Thus if newd and oldd are duplicate refer-
ences 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 newd is specified. If this descriptor is already in use, the descriptor is first deallocated as
if a close(2) call had been done first.
RETURN VALUES
The value -1 is returned if an error occurs in either call. The external variable errno indicates the cause of the error.
ERRORS
Dup() and dup2() fail if:
[EBADF] Oldd or newd is not a valid active descriptor
[EMFILE] Too many descriptors are active.
SEE ALSO
accept(2), open(2), close(2), fcntl(2), pipe(2), socket(2), socketpair(2), getdtablesize(2)
STANDARDS
Dup() and dup2() are expected to conform to IEEE Std 1003.1-1988 (``POSIX.1'').
4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution