-
Notifications
You must be signed in to change notification settings - Fork 215
/
reptyr.1
185 lines (156 loc) · 4.45 KB
/
reptyr.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
.mso www.tmac
.TH reptyr 1 "03 Feb 2011"
.SH NAME
reptyr \- Reparent a running program to a new terminal
.SH SYNOPSIS
.B reptyr
.I PID
.B reptyr \-l|\-L [COMMAND [ARGS]]
.SH DESCRIPTION
.B reptyr
is a utility for taking an existing running program and
attaching it to a new terminal. Started a long-running process over
ssh, but have to leave and don't want to interrupt it? Just start a
screen, use
.B reptyr
to grab it, and then kill the ssh session and head
on home.
.LP
.B reptyr
works by attaching to the target program using
.BR ptrace (2),
redirecting relevant file descriptors, and changing the program's controlling
terminal (See
.BR tty (4))
It is this last detail that makes
.B reptyr
work much better than alternatives such as
.BR retty (1).
.LP
After attaching a program, the program will appear to be either backgrounded or
suspended to the shell it was launched from (depending on the shell). For
maximal safety you can run
.IP
bg; disown
.LP
in the old shell to remove the association with the program, but
.B reptyr
will attempt to ensure that the target program remains running even if you close
the shell without doing so.
.SH OPTIONS
.B \-T
.IP
Use an alternate mode of attaching, "TTY-stealing". In this mode,
.B reptyr
will not
.BR ptrace (2)
the target process, but will attempt to discover the terminal emulator
for that process' pty, and steal the master end of the pty. This mode
is more reliable and flexible in many circumstances (for instance, it
can attach all processes on a tty, rather than just a single
process). However, as a downside, children of
.BR sshd(8)
cannot be attached via
.B -T
unless
.B reptyr
is run as root. See
.URL https://blog.nelhage.com/2014/08/new-reptyr-feature-tty-stealing/
for more information about tty-stealing.
.LP
.B \-l, \-L [COMMAND [ARGS]]
.IP
Instead of attaching to a new process, create a new pty pair, proxy the master
end to the current terminal, and then print the name of the slave pty. This can
be passed to e.g.
.B gdb\'s
.I set inferior-tty
option.
If an optional
.B COMMAND
and
.B ARGS
are passed in conjunction with
.B -l,
that command will be executed as a child of
.B reptyr
with the
.B REPTYR_PTY
environment variable set to the name of the slave pty. If
.B -L
is used instead of
.B -l,
then fds 0-2 of the child will also be redirected to point to the
slave, and the child will be run in a fresh session with the slave as
its controlling terminal.
.LP
.B \-s
.IP
By default, reptyr will move any file descriptors in the target that were
connected to the target's controlling terminal to point to the new terminal. The
.B -s
option will cause reptyr to unconditionally attach file descriptors 0, 1, and 2
in the target, even if the target has no controlling terminal or they are not
connected to a terminal.
.LP
.B \-v
.IP
Print the version of
.B reptyr
and exit.
.LP
.B \-h
.IP
Print a usage message and exit.
.LP
.B \-V
.IP
Print verbose debug output while running.
.LP
.SH NOTES
.B reptyr
depends on the
.BR ptrace (2)
system call to attach to the remote program. On Ubuntu Maverick and higher, this
ability is disabled by default for security reasons. You can enable it
temporarily by doing
.IP
# echo 0 > /proc/sys/kernel/yama/ptrace_scope
.LP
as root, or permanently by editing the file
.IR /etc/sysctl.d/10-ptrace.conf ,
which also contains more information about this setting.
.SH BUGS
When attaching to some curses programs, they will not redraw the screen right
away, and a
.B ^L
or similar will be needed to force a redraw.
Similarly, after attaching to certain programs, the old terminal will be left in
an odd state, and a
.B clear
or even
.B reset
may be required before the old terminal is usable again.
Attaching to rtorrent (and probably some other apps) doesn't work right
(rtorrent stops accepting input) (The problem is that rtorrent is using epoll to
poll stdin, and we don't update the internal reference that the epoll fd has to
the old tty).
Attaching to a process with children doesn't work right. This should be possible
to fix -- I just need to ptrace each child individually and do the same games to
it.
Attaching a
.BR less (1)
process doesn't work if you have a
.I .lessfilter
file, as
.BR less
leaves around a zombie child in this case. This could be worked around.
Bugs should be reported to the author (see below) or via the issue tracker on
GitHub.
.SH AUTHORS
reptyr was written by Nelson Elhage <[email protected]>.
.SH HOMEPAGE
.URL https://github.com/nelhage/reptyr
.SH SEE ALSO
.BR neercs (1),
.BR screen (1)