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.
We can just use git to download the sources:
git clone https://github.com/nelhage/reptyr
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
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!