How long can $DISPLAY environment variable value be?
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?
Solution 1:
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.