Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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 wrote a 'lil Linux assembler app that forks the current process and then executes a second app.
The current process waits for the other one to end and then continues.
The second is an app I wrote in C which reads certain environment variables.
Cool, great, it works fine, except...
When I execute it from the first app then it cannot read the environment variables, but if I just run it plain vanilla then it can.
I also noticed that there are some other executables which I cannot exec at all, like mount.
Can someone explain this to me?
What am I not doing?
If you don't pass the parents environment to the child then the child will just start with a default empty environment. Look at the exec calls with the v in the name like execv which allows you to pass an environment to the child process.
The environment variables i'm talking about are the global ones, shown when you type "env".
Isn't there a way I can just tell the child to run in the same environment as the parent is in?
...and why would this stop apps like "mount" from working?
The child does run in the same environment that the parent does, including global environment variables. and you get them the same way; using the getenv() system call. Make sure the variables are exported from your shell and aren't just shell local. setenv() will export them from a program.
As for mount, make sure the arguments that you pass match what you would put on the command line and remember that most mount commands must run as root. Could be the path part too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.