Thu . 19 Aug 2019
TR | RU | UK | KK | BE |

dup (system call)


In Unix-like operating systems, dup and dup2 system calls create a copy of a given file descriptor This new descriptor actually does not behave like a copy, but like an alias of the old one

Contents

  • 1 C library POSIX definition
  • 2 Importance of dup2 for Unix shells
  • 3 Use in Perl language
  • 4 See also
  • 5 References

C library POSIX definitionedit

These dup and dup2 calls are standardized by the POSIX specification

int dup int oldfd; int dup2 int oldfd, int newfd;

The former allocates the first available descriptor, just like open behaves; an alternative way to duplicate a file descriptor to an unspecified place is the fcntl system call with F_DUPFD command

The latter places a copy to a specified location index, closing a file descriptor if it already exists

Importance of dup2 for Unix shellsedit

Unix shells use dup2 for input/output redirection Along with pipe, it is a tool on which Unix pipes rely

The following example uses pipe and dup in order to connect two separate processes program1 and program2 using Unix pipes:

#include <stdioh> #include <stdlibh> #include <unistdh> / function prototypes / void dieconst char; int mainint argc, char argv else return 0; void dieconst char msg

Use in Perl languageedit

Perl does not provide these system calls directly But dup2 to redefine one of standard streams may be invoked via "pipe opens" technique, using the vertical bar character in the file path for the open call Namely,

open FILE, "| shell command"

performs pipe, fork, dup2…,STDIN and then executes a specified command Likewise,

open FILE, "shell command |"

performs pipe, fork, dup2…,STDOUT and then executes a specified command


See alsoedit

  • File descriptor – how it works and other functions related to open

Referencesedit

  • Advanced Programming in the UNIX Environment by W Richard Stevens ISBN 81-7808-096-6


dup (system call) Information about

dup (system call)


  • user icon

    dup (system call) beatiful post thanks!

    29.10.2014


dup (system call)
dup (system call)
dup (system call) viewing the topic.
dup (system call) what, dup (system call) who, dup (system call) explanation

There are excerpts from wikipedia on this article and video

Random Posts

Amorphous metal

Amorphous metal

An amorphous metal also known as metallic glass or glassy metal is a solid metallic material, usuall...
Arthur Lake (bishop)

Arthur Lake (bishop)

Arthur Lake September 1569 – 4 May 1626 was Bishop of Bath and Wells and a translator of the King Ja...
John Hawkins (author)

John Hawkins (author)

Sir John Hawkins 29 March 1719 – 21 May 1789 was an English author and friend of Dr Samuel Johnson a...
McDonnell Douglas MD-12

McDonnell Douglas MD-12

The McDonnell Douglas MD-12 was an aircraft design study undertaken by the McDonnell Douglas company...

Random Posts (searchxengine.com)

Shtiintsa

Shtiintsa

Shtiintsa Rugby Club Baia Mare - Romanian rugby club from Baia Mare, playing in the Super League Clu
Entelop (district)

Entelop (district)

Antelope County is the county located in the state of Nebraska of the United States with a populatio
Rosario, Amed

Rosario, Amed

Herman Amed Valdez Rosario Isp German Amed Valdez Rosario, November 20, 1995, Santo Domingo - Domini
Thirteenth tale

Thirteenth tale

novel Author: Diane Setterfield Original language: English Date of writing: 2006 Date of firs