What are Terminal Multiplexers?

What are Terminal Multiplexers?

Terminal Multiplexers and their use.

Macintosh terminal

Introduction to Multiplexers

Has it ever happened to you that you have used a limited resource and were forced to wait for specific processes to complete before continuing your interaction with it? If yes, multiple frustrations.

The satisfaction one gets if one discovers that one can run multiple instances of a program at the same time without having to worry about session limitations, is limitless.

Multiplexing (mixing) - This is where multiple analog or digital signals are merged into one signal. This is done to share scarce resources.

Terminal - This is an interface that allows us to interact with a system or computer and its processes.

Why Multiplexing?

many requests and commands to one resource

This enables any user to run many processes at the same time.

Multiplexing helps especially when sharing a limited resource like a server, computer, programs, networking, and many more.

A system for making multiple calls/conversations simultaneously. Multiplexing is also used in telecommunications.

How to do multiplexing in the terminal

This is where terminal multiplexing tools come in.

These tools enable several terminals (or windows) to be created, accessed, and controlled from a single screen.

There are many tools:

In Linux: - Openbox, Zellij, GNU Screen/Screen, tmux, Tmuxinator, Byobu, 3mux, vtm, mtm, dvtm, wezterm.

In Windows - tmux, conemu, GNU Screen, console, vtm.

In MacOs - iTerm2, Terminator, GNU Screen, Tmux, csshX, SecureCRT, Amethyst.

These tools have different limitations since most are open source. Kindly look up their documentation to understand more about them.

How do multiplexers work?

For this illustration of how terminal multiplexers work, let us use TMUX:

Why tmux? Tmux is open-source and feature-rich to help you perform tasks synchronously increasing productivity.

Installation.

  1. Linux:

    Some Linux Distros have their processes of installation:

    Ubuntu and many other Distros:

     sudo apt install tmux
    

    Fedora:

     sudo dnf -y install tmux
    

    Check the version installed:

     tmux –version
    
  2. Mac Os:

      sudo port install tmux
    

    or

     brew install tmux
    

    Check and Upgrade tmux files:

     port contents tmux
    
  3. Windows OS:

There are many ways to install tmux on Windows. Try out which is more preferable and easiest way to install.

Options:

  1. Using WSL.

    • Install WSL (Windows Subsystem for Linux) and your preferred distro. use CMD or Windows Terminal: Here is a complete guide - (wsl installation).

    • Use VMWare or virtual machines installed on your preferred distro.

    • Sometimes WSL fails and produces an error 0x8000ffff: This error occurs if your OS Version is not higher than specified or when there is a system error.

  2. Using Gitbash.

    • Install git with git bash (Here is a guide: git bash installation guide ).

    • Then Install msys2(here is an installation guide mysys2 guide).

    • pen mysys2 and install tmux.

    • Copy the tmux and msys-event binaries from the msys2 bin folder (probably C:\msys64\usr\bin) to the git bash bin folder (probably C:\Program Files\Git\usr\bin).

    • Restart Gitbash.

    • Type tmux in the GitBash terminal.

Check out this info to configure your git bash: (git bash configuration).

  1. Using VMWare or virtual machines.

    • Sometimes WSL fails and produces an error 0x8000ffff: especially if your OS Version is not higher than specified or system error. You must run Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.

    • When unable to figure it out, Install a VMWare of your choice.VMware Fusion and Virtualbox to name a few.

    • Use a Linux distro of your choice and configure it to your VMWare.

    • Open your Linux distro in VMWare and launch the terminal.

    • Then install tmux.

Disclaimer: Sometimes tmux has issues with other Operating Systems.

It works great with Linux distros.

Basic Commands in Tmux.

tmux commands use 2 keys to operate or rather, tmux has a prefix. The default one is Ctrl+b(Linux and Windows).

How does the tmux prefix work?

You'll be able to enter your command instantly when you press Control + b(Windows and Linux) or Command + b (Mac OS) simultaneously.

Ctrl+b, Then the command to specify the action.

e.g. ctrl+b, " - to split window panes from top to bottom.

tmux Commands:

tmux - launches the tmux terminal multiplexer.

Prefix + ...

  1. - Split the windowpanes from top to bottom.

  2. % - Split the window panes from left to right.

  3. The right arrow key - will shift from the active window to the next right-docked window pane.

  4. The left arrow key - will shift from the active window to the next left-docked window pane.

  5. The Top arrow key - Navigate to the top window pane.

  6. The Bottom Arrow key - Navigate to the bottom window pane.

  7. ; - toggle between panes

  8. C - Create a simple navigation at the bottom - use Prefix + N and Prefix + P to move to the next or previous pane.

  9. Q - Show window pane numbers.

  10. W - List all windows in all sessions.

Sessions.

Sessions allow the attachment and detachment of processes active in a window or terminal.

This allows multiple users to use the same resources when attached.

How to list Sessions:

tmux ls
tmux lsc
tmux -list-sessions

Additionally, it tells you if the sessions are attached

How to Use sessions in tmux.

  1. Create sessions.

    tmux new -s <session name>

     tmux new -s top_network
     tmux new -s log_network
    
  2. Attach Sessions.

    In the current session, you can attach it to the other session as follows:

    tmux attach -t <other session name>

     Tmux attach -t top_network
    
  3. Detach Session.

    Prefix + d // Ctrl + b, d

  4. Reattach session.

     tmux attach
    

Disadvantages of Multiplexers.

Multiplexers serve many purposes and increase productivity. However, I have not heard any cons about the use of multiplexing software.

However, opening many windows at once may seem tedious and confusing. I limit myself to at most 4 window panes. I am human and it keeps reminding me that I need a bigger screen🤣🤣.

Either way, it may be easy or hard to configure according to your computer and software skills if you are a beginner at using multiplexers.

Conclusion:

Multiplexers will help you run tail logs, debug, run services, and run tests to our system while monitoring the system synchronously without having to wait for processes to finish.

Multiplexers are quite a save especially when working on a highly demanding project.

There are many multiplexers for all platforms. Your preferences matter according to the tools you need for development and productivity.

Join the adventure and follow along!

Twitter - twitter.com/Moses_Morrisdev

Github - github.com/Moses-Morris