DUPX

Section: User Commands (1)
Updated: Version 436: 07 Jul 2009
Index Return to Main Contents

 

NAME

dupx - redirect input/output/error of a running process

 

SYNOPSIS

dupx [-q] [-o ofile] [-e efile] [-i ifile]
[-n fd:filename] <pid>
dupx [-q] <pid>

 

DESCRIPTION

Dupx is a simple utility to remap files of an already running program. Shells like Bash allow easy input/output/error redirection at the time the program is started using >, < - like syntax, e.g.:
echo 'redirect this text' > /tmp/stdout
will redirect output of echo to /tmp/stdout.

Standard shells however do not provide the capability of remapping (redirecting) of output (or input, or error) for an already started process. Dupx tries to address this problem by using dup(2) system call from inside gdb(1). Dupx is currently implemented as a simple shell wrapper around a gdb script.

 

OPTIONS

In the first form of its invocation, the user can optionally specify where he wants input/output/error to be using:
-o ofile
redirects the remaining of standard output (assumed to correspond to file descriptor 0) to the filename ofile. This file is opened in write-only, append-to mode. It's created if it does not already exist.
-i ifile
redirects the remaining of standard input (assumed to correspond to file descriptor 1) to the filename ifile. This file is opened in read-only mode.
-e efile
redirects the remaining of standard error (assumed to correspond to file descriptor 2) to the filename efile. This file is opened in write-only, append-to mode. It's created if it does not already exist.
-n fd:filename
remaps the file descriptor fd to the filename. This file is opened in read-write, append-to mode. It's created if it does not already exist. This option can be specified multiple times for different descriptors.
-q
Be as quiet as possible.

In the second form of its invocation, dupx remaps the standard input, output, and error from the current command line into the process specified by pidR.

 

EXAMPLE USAGE

Note that these examples use bash syntax. First, we start a background bash job that sleeps, then prints something on standard output:
bash -c 'sleep 1m && echo rise and shine' &
1. Redirect the remainder of standard output to /tmp/stdout
The following invocations are equivalent:
dupx -n 0:/tmp/test $!
dupx -o /tmp/test $!
dupx $! >>/tmp/test
Note that the last example also remaps stderr and stdin of the process. But because the target process was started on the same tty as dupx is being run, they are effectively unchanged.
2. Redirect the remainder of stdout, and stderr to different files, read the rest of stdin from /dev/null:
The following invocations are equivalent:
dupx -o /tmp/stdout -e /tmp/stderr -i /dev/null $!
dupx -n 0:/tmp/stdout 1:/dev/null 2:/tmp/stderr $!
dupx >/tmp/stdout 2>/tmp/stderr </dev/null $!

 

LIMITATIONS

You must have permissions to access the process that you are trying to remap.
To remap stdin/stdout/stderr of a process to the current ones, you need to have proc(5) file system support.

 

SEE ALSO

dup(2), gdb(1), bash(1), screen(1), proc(5)

 

COPYRIGHT

Copyright (C) 2009-2010 Yuri Pradkin
Distributed under license GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

dupx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

 

AUTHOR

Yuri Pradkin <yuri@isi.edu>
For more information, see the dupx homepage at
http://www.isi.edu/~yuri/dupx


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
EXAMPLE USAGE
LIMITATIONS
SEE ALSO
COPYRIGHT
AUTHOR

This document was created by man2html, using the manual pages.
Time: 20:21:05 GMT, August 12, 2010