LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-13-2022, 05:20 PM   #1
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,079

Rep: Reputation: Disabled
How can the same variable have different values at the same time???


I am trying these settings in ~/.profile
Code:
export XDG_CACHE_HOME=/run/user/$(id -u)
export XDG_RUNTIME_DIR=/run/user/$(id -u)
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?
 
Old 05-13-2022, 05:32 PM   #2
LuckyCyborg
Senior Member
 
Registered: Mar 2010
Posts: 3,630

Rep: Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516Reputation: 3516
Quote:
Originally Posted by Didier Spaier View Post
I am trying these settings in ~/.profile
Code:
export XDG_CACHE_HOME=/run/user/$(id -u)
export XDG_RUNTIME_DIR=/run/user/$(id -u)
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.
 
2 members found this post helpful.
Old 05-13-2022, 05:58 PM   #3
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,079

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by LuckyCyborg View Post
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.
 
Old 05-13-2022, 06:10 PM   #4
henca
Senior Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 1,024

Rep: Reputation: 690Reputation: 690Reputation: 690Reputation: 690Reputation: 690Reputation: 690
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.

regards Henrik
 
2 members found this post helpful.
Old 05-13-2022, 08:54 PM   #5
Pithium
Member
 
Registered: Jul 2014
Location: Far side of the Oregon Trail
Distribution: Slackware64 15.0
Posts: 508

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
If env variables were shared across multiple shell sessions that would make running multiple SlackBuild scripts at the same time very interesting.
 
Old 05-13-2022, 09:59 PM   #6
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado, USA
Distribution: Slackware
Posts: 930

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
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.
 
Old 05-13-2022, 10:26 PM   #7
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Yes, what henca said.

When a new process is created, it inherits the env var values of its parent process, but keeps its own copy of them, and can change them.

If you run the command "ps auxe | less" you can see each process' environment. Be warned that it's ungainly and awkward to read.
 
Old 05-14-2022, 01:16 AM   #8
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 15.0
Posts: 625

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
It's called Quantum Theory.
 
Old 05-14-2022, 12:30 PM   #9
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,079

Original Poster
Rep: Reputation: Disabled
I mark this thread as [SOLVED]

Still I will not use the settings I wrote in the initial post this thread, but rather put these lines in /etc/skel/.profile in Slint 15.0:
Code:
export XDG_RUNTIME_DIR=/run/user/$(id -u)
export XDG_CACHE_HOME=/dev/shm/$(whoami)
mkdir -p /dev/shm/$(whoami)
chmod 700 /dev/shm/$(whoami)
Rationale:
  • 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:
Code:
tmpfs   /dev/shm   tmpfs   nosuid,nodev,noexec,size=110%  0 0
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.
 
Old 05-14-2022, 12:34 PM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,264

Rep: Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340Reputation: 5340
Quote:
Originally Posted by Didier Spaier View Post
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?
They set it.

https://man7.org/linux/man-pages/man3/setenv.3.html

EDIT:

In the case of LxQt (I just checked), it's set in the "startlxqt" script.

Last edited by dugan; 05-14-2022 at 12:41 PM.
 
Old 05-14-2022, 12:52 PM   #11
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,079

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
They set it
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Different mount checking values for 2 same size HDDs rohitchauhan Linux - General 2 01-07-2016 09:13 PM
[SOLVED] How to match different records based on Same Field values using awk Abdelrahman.fathy Programming 22 11-11-2015 10:32 PM
[SOLVED] Two dead hard drives at the same time, different brands, different age? lpallard Linux - Hardware 12 07-02-2013 12:00 PM
[SOLVED] awk: same test on same file by different scripts gives different result porphyry5 Programming 1 09-30-2012 05:26 AM
[SOLVED] Two pointers, that have the same address point to different values??? alephan Programming 8 05-03-2011 04:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration