The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 08:22 PM
Testing the forking process. Vitamin254 UNIX for Dummies Questions & Answers 0 02-22-2008 08:12 PM
forking process. kymthasneem High Level Programming 2 06-23-2007 10:00 AM
forking a new process themezzaman High Level Programming 4 06-20-2006 01:13 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 02:41 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-21-2008
Registered User
 

Join Date: Dec 2007
Posts: 106
Question VERY confused about forking of child process

hi,

I thought that when a child shell is forked, it will inherit all the variables of the parent

now in my .cshrc I have

Code:
setenv X x
then I do at command line

Code:
setenv X y
and X is now y. So far so good!

I then have a very simple script, y.csh

Code:
#!/usr/bin/csh

echo X
Now when I do

Code:
%: y.csh
x gets printed. Why? I thought the child will inherit all the variables of its parent. So it should inherit X as y, yes?

thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 02-21-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Works as expected for me

Code:
%setenv X x
%echo $X
x
%setenv X y
%echo $X
y
%cat t
#!/usr/bin/csh

echo $X
%./t
y
%
Reply With Quote
  #3  
Old 02-22-2008
Registered User
 

Join Date: Dec 2007
Posts: 106
no, I think you missed the bit that my .cshrc also sets X (to x)

thanks
Reply With Quote
  #4  
Old 02-22-2008
Registered User
 

Join Date: Feb 2008
Posts: 91
Quote:
Originally Posted by JamesByars View Post
hi,

I thought that when a child shell is forked, it will inherit all the variables of the parent

now in my .cshrc I have

Code:
setenv X x
then I do at command line

Code:
setenv X y
and X is now y. So far so good!

I then have a very simple script, y.csh

Code:
#!/usr/bin/csh

echo X
Now when I do

Code:
%: y.csh
x gets printed. Why? I thought the child will inherit all the variables of its parent. So it should inherit X as y, yes?

thanks.
There is nothing strange in the output.
going through your "y.sh", you gave "echo X" - which will print "X"
if you want to print value in variable X, you should have given "echo $X"
Reply With Quote
  #5  
Old 02-22-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Unless it is a requirement, consider using a shell that does not have the problems csh has.

Here is an article, feel free to disagree:
into the wibble [csh is bad]
Reply With Quote
  #6  
Old 02-22-2008
Registered User
 

Join Date: Dec 2007
Posts: 106
sorry, I DO have echo $X.

Code:
#!/usr/bin/csh

echo $X
To sum up, this is what is happening:

1) .cshrc sets X to x
2) I setenv X y in my shell
3) I then do y.csh

Now I know .cshrc will be called everytime a csh script is called. And obviously in this script we;re setting X to x. But I also thought that the child shell will inherit all the parents variables. So I would have expected it to inherit X = y, and for this to overrride whatever is happening in the .cshrc!

thanks.
Reply With Quote
  #7  
Old 02-22-2008
Registered User
 

Join Date: Jul 2007
Posts: 93
Please do a "man csh"
-f Suppress execution of the .cshrc file

change your script from:

Code:
#!/usr/bin/csh
echo $X
to:
Code:
#!/usr/bin/csh -f
echo $X
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0