FUN WITH LINUX

reptyr - A tool for "re-ptying" programs

3 February 2016

It happens so often that when I start a copy-job remotely, I just realize that I forgot to start it in GNU screen. Sometimes I can just stop the job and start it again in screen, but very often stopping the job might be problematically. There is a nice tool called reptyr which can re-ptying your jobs.

Downloading

We can just use git to download the sources:

git clone https://github.com/nelhage/reptyr 

Compiling:

make
cc -Wall -Werror -D_GNU_SOURCE -g -c -o reptyr.o reptyr.c
cc -Wall -Werror -D_GNU_SOURCE -g -c -o reallocarray.o reallocarray.c
cc -Wall -Werror -D_GNU_SOURCE -g -c -o attach.o attach.c
cc -Wall -Werror -D_GNU_SOURCE -g -c -o platform/linux/linux_ptrace.o platform/linux/linux_ptrace.c
cc -Wall -Werror -D_GNU_SOURCE -g -c -o platform/linux/linux.o platform/linux/linux.c
cc reptyr.o reallocarray.o attach.o platform/linux/linux_ptrace.o platform/linux/linux.o -o reptyr

Preparing the system

echo 0 > /proc/sys/kernel/yama/ptrace_scope

Or make it permanently by using the /etc/sysctl.conf:

echo "kernel.yama.ptrace_scope = 0" >> /etc/sysctl.conf
sysctl -p

Using repty

reptyr PID

Some problems

I did some tests with shell-scrips(using sleeep) and I wasn’t able to repty them. But even though, this programm is super useful!

[ Linux  Sysadmin  Bash  Tricks  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti