Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dup(2) [hpux man page]

dup(2)								System Calls Manual							    dup(2)

NAME
dup - duplicate an open file descriptor SYNOPSIS
DESCRIPTION
fildes is a file descriptor obtained from a or system call. returns a new file descriptor having the following in common with the origi- nal: o Same open file (or pipe). o Same file pointer (i.e., 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). The file descriptor returned is the lowest one available. RETURN VALUE
Upon successful completion, the file descriptor is returned as a non-negative integer. Otherwise, a value of -1 is returned and is set to indicate the error. ERRORS
fails if one or more of the following is true: fildes is not a valid open file descriptor. Request violates the maximum number of open file descriptors. AUTHOR
was developed by AT&T and HP. SEE ALSO
close(2), creat(2), dup2(2), exec(2), fcntl(2), open(2), pipe(2), privileges(5). STANDARDS CONFORMANCE
dup(2)

Check Out this Related Man Page

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)
Man Page

15 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

File status - open/close ??

Is there any commands in UNIX, like isopen(),isclose() to know whether a file has been opened for read/write purpose.? Thanks (3 Replies)
Discussion started by: Pal
3 Replies

2. UNIX for Dummies Questions & Answers

System Calls

What does the system call "dup" do? What is the difference between dup and dup2 I have a fair idea of what it does but I am confused when its coming down to the exact details... Please help me!:confused: (2 Replies)
Discussion started by: clickonline1
2 Replies

3. Programming

dup()

Would anyone be so kind to explain to me the function of dup() in UNIX? As far as I am concerned, it duplicates a file descriptor. Under what circumstances would we need to duplicate a file descriptor in a UNIX environment? Thank you. vinchen (3 Replies)
Discussion started by: vinchen
3 Replies

4. UNIX for Dummies Questions & Answers

LP error

Quick question: System HP 10.3 Sub system lp When trying to pipe to an lp get the following error: Unable to open file: lp -d zzzzz_eng -s error 9 Any help greatly appreciated. Gary (3 Replies)
Discussion started by: gseibold
3 Replies

5. UNIX for Dummies Questions & Answers

System calls?

open, creat, read, write, lseek and close Are they all primitive? :confused: *Another Question: is there a different between a system call, and an i/o system call? (2 Replies)
Discussion started by: PlunderBunny
2 Replies

6. Shell Programming and Scripting

Passing a file descriptor

I am trying to right a function which uses a file descriptor to write to a log file. The problem is that the on the print statement the file descriptor is called bad. Now when I first open the file and print to it in the f_open function by passing the descriptor to f_print_log all works well,... (6 Replies)
Discussion started by: robotball
6 Replies

7. Programming

dup()

when i want to replace standard output with output file int out; out = open("out", O_WRONLY)p; dup2(out,1); What Shall I do in case of appending??? I am using here O_WRONLY TO WRITE.BUT IF i wanna append, whats the word? (5 Replies)
Discussion started by: joey
5 Replies

8. UNIX for Dummies Questions & Answers

Write/read to file descriptors

Is it possible to write to file descriptor 0 and read from 1 or 2? How could this be implemented? (3 Replies)
Discussion started by: machshev
3 Replies

9. UNIX for Dummies Questions & Answers

how to access files via their descriptors?

hello, I'm new here, and new to Linux. I was wondering how to get hold of a certain file's descriptor, and how to use that number so that I access the contents of the file. please give me a full example, that is (1) how to determine the descriptor and (2) what magic symbols to use so that... (4 Replies)
Discussion started by: ialoq
4 Replies

10. Programming

Some how the open(file,flag, acc) returns 0 and write to the screen, instead of the file ???

I am out of idea what to do to resolve the problem! I need to use the open(file, for.., access) function to write a file. Never have the situation like that: it is return 0 - zero. As a result all write(..) going to the screen! What the problem it could be? I do not even know... (2 Replies)
Discussion started by: alex_5161
2 Replies

11. UNIX for Dummies Questions & Answers

Difference between file descriptor and file pointer

hi...., can anyone tell me what is the exact difference between file descriptor and file pointer...... and why file descriptor takes integer value???:confused: (10 Replies)
Discussion started by: jimmyuk
10 Replies

12. UNIX for Dummies Questions & Answers

vi does not open file properly....

Hello all, I am trying to edit a file using VI on hp-ux....but when i try to open the file using vi <filename> it dose not let me open up the right way...it just messes up the whole file....i cant even read that file...so for example...here is a file i created test1.txt...when i cat... (6 Replies)
Discussion started by: abdul.irfan2
6 Replies

13. Shell Programming and Scripting

file descriptor KSH

Hello, How can i use file descriptor in a script to read 2 files at the same time and extract line 200 from file 1 and line 500 from file 2. Thanks. (6 Replies)
Discussion started by: LiorAmitai
6 Replies

14. Shell Programming and Scripting

how to open a file and read a file in UNIX

HI can any one tell me how to open and read a file in UNIX actually i have the following script can you please suggest me on this.. LOG,">$log" or NotifyAdmin "Failed to open file $log";... this is the perl statement.. which opens log file. i want to open same log file in unix Thanks... (5 Replies)
Discussion started by: sravan008
5 Replies

15. UNIX and Linux Applications

Deja-dup make my / full. So I cannot restore my back up

The problematic directory is the following: /root/.cache/deja-dup This directory grows until my "/" is full and then the restoring activity fails. I already tried to create a symbolic link with origin another partition where I have more space. However during the restoring activity ... (4 Replies)
Discussion started by: puertas12
4 Replies