2

I am trying to compare these two methods of running multiple shells/processes by measuring memory and cpu usage via htop.

Can someone explain the differences in how each method functions, or if there are any?

EDIT:

From what I understand now, tmux/screen and other multiplexers are virtual sessions, i.e. multiple virtual sessions within the original session. This is in contrast to opening new tabs in terminal which are actually creating new sessions.

I have still not determined if there are performance benefits of one method over the other; nor the underlying mechanisms involved.

In the mean time, feel free to contribute more detailed knowledge about this topic!

These links below helped my understanding of the basic difference:

What's the relationship between multiplexer and terminal?

What are the benefits using terminal multiplexer

4

The biggest difference is that you can reattach to your screen or tmux sessions from other terminals (be they terminal emulators, VT's, SSH sessions, or even real serial terminals), but cannot do so with tabs in a terminal emulator. This may sound simple, but it brings up one of the biggest advantages to using screen or tmux, especially if you're dealing with a remote system: It can stick around beyond the duration of your current login session, which is immensely useful for a number of reasons.

There are a couple of other differences though:

  • Using screen or tmux means you will always have exactly one extra process per screen or tmux session (but not per window/tab). Dependent on the terminal emulator you use, you might have no extra processes, or you may have more than one extra.
  • Using screen or tmux gives you some extra functionality that most terminal emulators don't, such as split windows and the ability to send a BREAK on the application in the tab.
  • The hotkeys used to switch windows/tabs differ (though both can generally be reconfigured pretty easily).
  • You can use screen and tmux from any terminal session, but can only use tabs when using a terminal emulator.
  • Screen (and possibly tmux) provides a terminal locking feature. Essentially, it's equivalent to the screen lock you see in most desktops.

In both cases, each window/tab ultimately has one associated pseudoterminal (usually abbreviated PTY). The real difference here is just what's actually controlling which pseudoterminal your input is going to and output is displayed from. The exact mechanics of how a pseudoterminal works are a bit complicated, but well documented multiple places online. The basic idea is that it gives a process a way to pretend to be an actual hardware terminal so that it can run another process that expects to talk to a terminal.

Neither option is really all that much more efficient in terms of system resources, and which is more efficient in terms of UX is largely dependent on the user themself (for example, screen is more efficient for me, because I'm used to all the default key bindings).

  • Thanks! This was really helpful. So if I understand correctly, multiplexers are most useful for using remote logins because they 'save' your session in case of a timeout or connection disruption? – abdelmak Nov 28 '18 at 15:27
  • 1
    @abdelmak Yes, but it also has some practical applications beyond that. One big one is migrating sessions (eg, starting with a local session, then switching to a remote session later, or the reverse). – Austin Hemmelgarn Nov 28 '18 at 16:49
1

Both kinds of software actually use the same kind of pseudo-ttys, and both initialize the environment in much the same way.

The main difference is that multiplexers act like a 'proxy' – they act as terminal emulators to the program inside, but as regular programs (clients) to the main terminal emulator.

This means that each character or control code is interpreted twice as it goes through the layers. Both tmux and gnome-terminal keep their own state; they have their own idea of what the screen buffer is supposed to look like (and it may sometimes get out of sync).

It also means roughly twice the RAM requirement for the main & alternate buffers. Scrollback may be duplicated as well, though rarely (the outer terminal doesn't update scrollback because tmux has switched it to the 'alternate buffer').

  • The duplication of characters and control codes makes sense, but twice the RAM requirement also contradicts @Austin's claim that there is no difference in system resource usage. – abdelmak Nov 28 '18 at 15:38
  • There's usually no noticeable difference, unless you're trying to use a 10000x10000-cell terminal. Still, the multiplexer keeps its own buffer (that's how you can detach and later reattach and still get the same view), and that buffer has to be stored somewhere, consuming RAM space. All the processing it does has to use CPU time, too. – user1686 Nov 28 '18 at 15:42
  • 1
    @grawity And how often do you think it's really going to matter? Typical size of a terminal window at 1920x1080 with 12-point font translates to roughly 30kb of space needed for a full screen (assuming each cell is stored as a packed bitfield in a 32-bit integer, which is reasonable to assume in most cases), and the CPU time to process updates for that iis on the order of at most microseconds for most terminal emulators (and even less for multiplexers, because they don't have to make the GUI related calls to update things). – Austin Hemmelgarn Nov 28 '18 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.