Search code examples
perlprocessglobal-variablessystemscribe

Parent process variables inside Child process in Perl


  • I have a script execute.pl and it calls child.pl through system call.
  • I am creating an object of AppLogger in execute.pl
  • This AppLogger is package and an interface to my Scribe Logging server
  • Now in this AppLogger I am establishing a connection to my Scribe Logging server and has various funtions like sendlog which sends logs to server.

    execute.pl:

    use AppLogger;
    use strict;
    use warnings;
    
    my $logger = new AppLogger;
    system("perl child.pl")
    

As I know system is a OS call and child.pl will be completly different process but still Is there a way I can access $logger ie AppLogger object inside child.pl without re-creating an connection object each time I want to log.


Solution

  • No. system is a wrapper around fork+exec+wait. exec replaces the program executing in the process, including its heap (memory).