[SOLVED] How can the same variable have different values at the same time???
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
To test, I started 4 desktops at the same time: KDE (started with lightdm), MATE (started from tty2) XFCE (started from tty3) and LXQt (started from TTY4). I could check that /run/user/1000 was populated as expected and so far all DE seem to behave normally, but something puzzles me: typing "env|grep XDG" I see that XDG_CURRENT_DESKTOP is set respectively as KDE, MATE, XFCE and LXQT when I type the command from these desktops. Can it be that at each session opening the variable is stored at a new location in RAM, which is remembered only in this session? How does that work?
To test, I started 4 desktops at the same time: KDE (started with lightdm), MATE (started from tty2) XFCE (started from tty3) and LXQt (started from TTY4). I could check that /run/user/1000 was populated as expected and so far all DE seem to behave normally, but something puzzles me: typing "env|grep XDG" I see that XDG_CURRENT_DESKTOP is set respectively as KDE, MATE, XFCE and LXQT when I type the command from these desktops. Can it be that at each session opening the variable is stored at a new location in RAM, which is remembered only in this session? How does that work?
I'm not a programmer, but from what I know, I think that because on each console is spawned a specific Bash instance on login, and every instance has its own variables and data, because they are, well... executed instances of a particular program, each one being standalone, without data sharing.
Last edited by LuckyCyborg; 05-13-2022 at 05:39 PM.
I'm not a programmer, but from what I know, I think that because on each console is spawned a specific Bash instance on login, and every instance has its own variables and data, because they are, well... executed instances of a particular program, each one being standalone, without data sharing.
Well, that makes sense. I made a simple test setting the same variable from two ttys and indeed there seem to be an isolation.
Last edited by Didier Spaier; 05-13-2022 at 06:16 PM.
Yes, that is really the explanation. Environment variables are not only unique for each shell, but can be unique for every process. This can easily be verified by doing:
md5sum /proc/*/environ
Different processes will have different environment variables set giving different md5sums.
Bash is based on dynamic variable scoping. Most programming languages are based on static variable scoping.
Dynamic scoping is all about pushing the current environment down the stack of execution. Each stack can take on different values for variables with the same name.
The default size of /run/user/$(id -u) is 10% of the physical RAM size, which is a bit small if you have few physical RAM to host the cached files of an user.
The default size of /dev/shm is 50% of the physical RAM.
As an aside if you have a swap in zram you can increase the latter with no issue. To test I have written this line in /etc/fstab:
After a reboot I filled up /dev/shm copying big files in it. I was still able to run 3 DEs at the same time, with indeed several G of swap in zram as shown by df -th and zramctl but no swap on a drive needed, so systems still reasonably responsive.
Last edited by Didier Spaier; 05-14-2022 at 12:31 PM.
typing "env|grep XDG" I see that XDG_CURRENT_DESKTOP is set respectively as KDE, MATE, XFCE and LXQT when I type the command from these desktops. How does that work?
Yeah, I have spent a lot of time checking that the XDG variables that matter most be correctly set in the three ways of starting a desktop session (startx, sddm, lightdm) for all provided sessions (X11 only), listed below:
Code:
didier[~]$ session-chooser
Usage: /usr/bin/session-chooser <desktop session>
Available desktop sessions:
fvwm
lxqt
mate
plasma
plasma-safe
wmaker
xfce
The session is currently set for didier to lxqt.
didier[~]$
PS: before someone asks: no, twm, mwm, blackbox and fluxbox are not proposed. But you can use them as window manager and very easily if running LXQt (by the way openbox will be the default in LXQt, but not proposed standalone either).
PPS: And that works, I just checked. LXQt is really awesome.
Last edited by Didier Spaier; 05-14-2022 at 01:42 PM.
Reason: PS added.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.