ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I know theres a function out there in C to read and write enviornment variables. Could someone tell me what it is and describe its basic use? This would be for a linux system of course!
Once your C program ends, the environment your program was running in ends also and reverts back to the environment that you were using before you ran your program.
An attempt to clarify that some more: each process has it's own set of environment vars. But each process inherits (gets a copy) of the environment of its parent process.
When you start a program from a shell, the shell will be the parent of the process the program is running in. So the program gets a copy of the environment the shell has. Now if the program creates/changes environment vars, it does so in its own copy of the environment, which is discarded when the program exits.
There's no single way around this. If it were possible to get around this, it would be a security hole.
What you can do, is setting environment vars in your program and start another shell from your program with execl("/bin/bash") for example. The new shell then gets a copy of the environment from your program.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.