The "screen" window manager allows specifying the desired size of the scrollback buffer.

E.g. when starting a new session: (source)

‘-h num’
    Set the history scrollback buffer to be num lines high.
    Equivalent to the defscrollback command (see Copy).

Or when already inside a screen session with these commands: (source)

12.1.2 Scrollback
— Command: defscrollback num
           Same as the scrollback command except that the default
           setting for new windows is changed. Defaults to 100. 
— Command: scrollback num
           Set the size of the scrollback buffer for the current 
           window to num lines. The default scrollback is 100 lines.
           Use C-a i to view the current setting.

But I cannot seem to find documentation stating the maximum value for num for any of above approaches.

So the question is: how to determine the maximum scrollback length for the screen utility?


I'm not sure where to find it documented, but digging into the source a bit gives some clues. When you pass in -h it sets the histheight (see screen.c). In main it parses -h as follows:

case 'h':
    if (--argc == 0)
        exit_with_usage(myname, NULL, NULL);
    nwin_options.histheight = atoi(*++argv);
    if (nwin_options.histheight < 0)
        exit_with_usage(myname, "-h: %s: negative scrollback size?", *argv);

The nwin_options struct is an instance of NewWindow which is defined in window.h:

struct NewWindow {
    int StartAt;    /* where to start the search for the slot */
    char    *aka;       /* aka string */
    char    **args;     /* argv vector */
    char    *dir;       /* directory for chdir */
    char    *term;      /* TERM to be set instead of "screen" */
    bool    aflag;
    bool    dynamicaka;
    int flowflag;
    int lflag;
    int histheight;
    int monitor;
    int wlock;      /* default writelock setting */
    int silence;
    bool    wrap;
    bool    Lflag;      /* logging */
    int slow;       /* inter character milliseconds */
    int gr;
    bool    c1;
    int bce;
    int encoding;
    char    *hstatus;
    char    *charset;
    int poll_zombie_timeout;

where we can see that histheight is an int, so presumably the max value you can set it to is maxint for a signed int.

  • :-) crosspost. Thanks Eric, yous is a bit more factual answer. – Paul van Leeuwen Jun 24 '17 at 11:16
  • It seems the maximum value can differ per system. Here is a Q&A that deals with actually determining it on a system. – Paul van Leeuwen Jun 24 '17 at 11:19
  • 1
    @PaulvanLeeuwen and make sure you're using the same compiler as screen was compiled with. For example, if you did the test with a 64-bit compiler, but screen was compiled with 32-bit one, your value would be way off – Eric Renouf Jun 24 '17 at 11:21

While trying to answer my own question, this is what I found on my own system via trial-and-error:

answer: there is a hard-limit (somewhere between 50,000,000 and 1,000,000,000), but performance will probably be your bottleneck (as such I was not able to determine the exact hard-limit)

My experiments included:

Start a new screen session without having any ~/.screenrc configuration file:

screen -a

Inside screen open the screen command prompt by pressing ctrl+a,: and enter the command:

scrollback 1000000

which resulted in the message: scrollback set to 1000000 (1,000,000).

Trying scrollback 1000000000 (1,000,000,000) quite quickly resulted in the message scrollback set to 0. I assume this means that 1,000,000 is accepted and 1,000,000,000 is too much.

Trying scrollback100000000` (100,000,000) made screen hang. A second terminal session and some patience later I was able to kill screen. This behavior turned out to be consistent when trying the same thing again.

Trying scrollback 10000000 (10,000,000) with 2 seconds delay resulted in the message scrollback set to 10000000.

Trying scrollback 50000000 (50,000,000) with 60 seconds delay resulted in the message scrollback set to 50000000.

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.