Signup/Sign In
MARCH 27, 2023

Move processes to your terminal shell with reptyr

Technology #linux#ssh

    Have you ever been in a situation where a command which you started and accedently closed or lost access to the shell session from which you started that process or command? Also, the shell session is not made persistent with powerful tools like tmux, screen, etc. In this tutorial we will learn about the solution for this problem with a secretly powerful and amazing tool reptyr.

    You can move a running program from one terminal to another with the help of the Unix tool Reptyr. Because of its numerous features, Reptyr is an indispensable tool for Unix users.

    Benefits of using reptyr tool in Linux

    There are a number of important advantages for users of reptyr.

    1. First, it lets you switch between GUI and terminal applications without having to restart them or lose any data. When working with long-running processes or switching between terminal windows, this is especially helpful.
    2. It has ability to resume background processes without restarting the applications is yet another advantage. This means that you can continue working on a process even after you log out of the system or close the terminal window.
    3. reptyr doesn't force applications to start over, so even if you have to switch terminals or systems, you can continue working on a process.

    Installation of reptyr

    Reptyr installation requires a compiler and an operating system based on Unix. Follow these instructions to set up this tool:

    Run the following command on Debian/Ubuntu:

    sudo apt-get install reptyr

    Run the following command on Fedora/RHEL:

    sudo yum install reptyr

    Install Homebrew using the following command on MacOS:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    brew install reptyr

    How to use reptyr to transfer running Processes Between Terminal shells in Linux?

    Reptyr is a tool that lets users move running processes between terminals. The following is the fundamental syntax for using reptyr:

    reptyr PID

    where PID is the process ID you want to transfer. You can use the ps command to discover a process's PID. For instance:

    ps aux | grep <process name>

    Once you have the PID, just run the reptyr command, and the process will be moved to the terminal where you are currently running the command.

    pgrep top

    you need to have permissive ptrace settings for this to work. This is not the default on ubuntu, and can be changed temporarily by running (as root): echo 0 > /proc/sys/kernel/yama/ptrace_scope It can be changed permanently by editing the following file: /etc/sysctl.d/10-ptrace.conf

    Limitations of reptyr

    Despite its usefulness, there are a few drawbacks to keep in mind. First, processes that are attached to a terminal cannot be transferred using reptyr. You will not be able to transfer the process using reptyr if it is not connected to a terminal. Additionally, not all kinds of processes might be compatible with reptyr. Reptyr may not be able to transfer some processes, like background processes and daemons.

    Reptyr's compatibility with Linux-based operating systems is yet another drawback. You will not be able to use reptyr if you are running a different operating system, such as Windows or macOS.

    Conclusion

    reptyr is an life saving tool which you may use less frequently but it makes your life so much easier. Moving processes between terminal windows without stopping and starting them is easy using this tool.

    Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS