home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5728 < prev    next >
Encoding:
Text File  |  1992-09-04  |  1.5 KB  |  74 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!gatech!darwin.sura.net!wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!chx400!bernina!neptune!weingart
  3. From: weingart@inf.ethz.ch (Tobias Weingartner)
  4. Subject: fork and perl
  5. Message-ID: <1992Sep4.163557.19733@neptune.inf.ethz.ch>
  6. Followup-To: weingart@inf.ethz.ch
  7. Keywords: fork
  8. Sender: news@neptune.inf.ethz.ch (Mr News)
  9. Nntp-Posting-Host: tau.inf.ethz.ch
  10. Reply-To: weingart@inf.ethz.ch
  11. Organization: ETH - Switzerland
  12. Date: Fri, 4 Sep 1992 16:35:57 GMT
  13. Lines: 59
  14.  
  15.  
  16. Hello, I have need to fork of a process under perl,
  17. and then have that process modify certain variables
  18. under the parent one.
  19.  
  20. This does not seem to work. (Thinking about it, make me wonder.)
  21.  
  22. I.E The following should demonstrate what I need.
  23.  
  24.  
  25. $tmp = 1;
  26. print "X - $tmp\n";
  27.  
  28. if(fork() == 0){
  29.     #
  30.     # Do some timeconsuming task here
  31.     #
  32.     for($i = 0; $i < 10000; $i++){}
  33.  
  34.     $tmp = 2;
  35.     print "XX - $tmp\n";
  36.     exit(0);
  37. }
  38.  
  39. print "XXX - $tmp\n";
  40.  
  41. wait;
  42.  
  43. print "XXXX - $tmp\n";
  44.  
  45. exit(0);
  46.  
  47.  
  48. This prints out the following:
  49. X - 1
  50. XXX - 1
  51. XX - 2
  52. XXXX - 1
  53.  
  54. This shows that the child can no longer modify the parents
  55. variables.  Is this even REMOTELY possible, or do implementation
  56. details prevent this?
  57.  
  58. This is 
  59.  
  60. perl -v
  61.  
  62. This is perl, version 4.0
  63.  
  64. $RCSfile: perl.c,v $$Revision: 4.0.1.4 $$Date: 91/06/10 01:23:07 $
  65. Patch level: 10
  66.  
  67. Copyright (c) 1989, 1990, 1991, Larry Wall
  68.  
  69. Perl may be copied only under the terms of either the Artistic License or the
  70. GNU General Public License, which may be found in the Perl 4.0 source kit.
  71.  
  72. --Toby.
  73.  
  74.