Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • K kernel
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • erlends-os
  • kernel
  • kernel
  • Wiki
    • Abi
  • dup2

Last edited by Erlend Sveen Oct 16, 2019
Page history

dup2

Duplicate or replace a file descriptor.

Syntax

#include <unistd.h>

int dup2 (int oldfd, int newfd);

Parameters

  • oldfd

    The file descriptor to duplicate.

  • newfd

    The file new file descriptor to use. If -1, the implementation will select a free file descriptor.

Return Value

The return value is the value of the new file descriptor if successful. Otherwise, the return value is negative and errno is set:

  • EINVAL

    The oldfd argument is invalid: Negative or outside the allowed range.

  • EBADF

    Bad file descriptor.

Remarks

The reference count to oldfd will be increased by one. It may be closed and the file will still be available at the new file descriptor.

You may use dup2 to replace the usual standard input and output with a different file/device. In order to start a new program with a different set of input and output files, see posix_spawn.

Clone repository
  • abi
    • bind
    • chdir
    • close
    • closedir
    • dup2
    • exit
    • fstat
    • getcwd
    • getpgrp
    • getpid
    • gettimeofday
    • ioctl_fcntl
    • kill
    • link
    • lseek
View All Pages