LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 02-12-2002, 03:31 AM   #1
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Rep: Reputation: 15
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?
 
Old 02-12-2002, 03:57 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
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.
 
Old 02-12-2002, 04:34 AM   #3
sourceman
Member
 
Registered: Feb 2002
Posts: 48

Original Poster
Rep: Reputation: 15
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?
 
Old 02-14-2002, 02:20 AM   #4
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
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...
 
Old 02-14-2002, 02:31 AM   #5
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
Oops... did I say setenv()? s/b putenv().

Doing too much C++ with getters and setters.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to fork/ exec schneidz Programming 10 08-30-2005 11:50 AM
Programming: fork, exec and system memory atienza Programming 2 08-24-2005 07:26 AM
about fork() kpachopoulos Programming 2 02-14-2005 12:24 AM
what is the difference between Fork & exec augustus123 Linux - Newbie 1 11-29-2004 07:32 AM
fork() in c++ deveraux83 Programming 5 11-13-2004 03:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:52 PM.

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