Score:0

How long can $DISPLAY environment variable value be?

in flag

What is the maximum length that $DISPLAY environment variable value can take?

I understand that it is - hostname:displaynumber.screennumber

So will it be => max($DISPLAY) = max(hostname) + max (displaynumber) + max(screennumber)?

What is max length of hostname, displaynumber and screennumber on Linux?

cocomac avatar
cn flag
You have asked four different questions. I don't know about the hostname, but you almost certainly won't run into any issues with the DISPLAY variable being too long. There is probobly a limit, but you won't hit it with normal use.
in flag
I understand that. I need to know the limit though as I will be persisting this information. I cannot assign something too big (as I have limited space) and i cannot assign something too less that it does not gets captured completely in some cases.
Score:2
in flag

Environment variable length is controlled by MAX_ARG_STRLEN, which is a constant value defined as PAGE_SIZE*32 within the Linux kernel.

You can check your PAGE_SIZE value via Terminal like this:

getconf PAGE_SIZE

If you are running stock Ubuntu (or an official flavour), then the value will likely be 4096 (bytes).

So, with this in mind:

4096 * 32 = 131,072

As a result, the maximum length of an environment variable, be it $DISPLAY or any other, is 128KB. This works out to 131,072 single-byte ASCII characters.

in flag
Thanks @matigo. This is too big and potentially defines the length in general for all environment variable. I am interested particularly in $DISPLAY environment variable. How big can it get?
in flag
I suggest re-reading the first seven words of the answer. *All* environment variables have the same limit. Linux is not like George Orwell's *Animal Farm*; there are no environment variables that are more equal than others
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.