Answer the question
In order to leave comments, you need to log in
Where can I find the environment variable file?
After reading a lot of material, I still haven’t figured out where the file is located in which the environment variables are written (on many sites they indicated the paths on which I have nothing) and whether there is such a file at all or in the file it is only written which variables to create at the start of the process and they are stored in RAM? Is it possible to open this file for reading from my program and change some values in it or add new ones (not using setenv, putenv, but manually appending to the file)? What will happen?
Ps I googled for a very long time and honestly, but I could not find a clear answer, please explain on your fingers
Answer the question
In order to leave comments, you need to log in
Almost every distribution uses pam_env, which reads settings from /etc/security/pam_env.conf and /etc/environment. Usually it is enabled for login, ssh, cron, and thus the variables set in these files will be visible to all processes launched from the console or by schedule.
In addition, variables can be set in local and global shell configs (/etc/profile, /etc/profile.d/*, /etc/bashrc, ...) , but this will only affect processes started from the shell.
There may also be some distribution-specific options, for example, Gentoo has a system-wide /etc/env.d/*
But in general, it depends on the way the software is launched, which needs to be fed a variable. Maybe you need to specify something in its configs. To pass specific variables to daemons, Debian typically uses /etc/default/{service_name}, while RedHat uses /etc/sysconfig/{service_name}. But it's worth checking the daemon's init file to see if it reads these configs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question