LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Fork 'n Exec (https://www.linuxquestions.org/questions/linux-general-1/fork-n-exec-14080/)

sourceman 02-12-2002 03:31 AM

Fork 'n Exec
 
I was messing around with fork...

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?

Mik 02-12-2002 03:57 AM

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.

sourceman 02-12-2002 04:34 AM

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?

Malicious 02-14-2002 02:20 AM

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.

If you have all that stuff right, beats me...

Malicious 02-14-2002 02:31 AM

Oops... did I say setenv()? s/b putenv().

Doing too much C++ with getters and setters.


All times are GMT -5. The time now is 06:14 AM.