perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raymond Wan <>
Subject Setting LD_LIBRARY_PATH for a forked process
Date Fri, 09 Jan 2009 09:08:16 GMT

Hi all,

I'm developing a web server which forks a process and then the child process goes off and
does some processing and I do not want to wait for it to return.  The child process runs a
C++ program (i.e., not a Perl script).  Thanks to replies here a while back, I got things
working by performing a "fork" followed by a "system".  So all was well...

Now, things have changed slightly and the C++ program needs to make use of shared libraries
and right now, it cannot find them.  Does anyone have any suggestions on how I would do that?
 Obviously, I need to update $LD_LIBRARY_PATH; but how would I do it?  Currently, I'm doing
something like this:

use Env qw(LD_LIBRARY_PATH);

my $cmd = "...";
my @args = ("...");

$ENV{LD_LIBRARY_PATH} = "<new path>";  ##  Or prepend to it

my $kid = fork;
if (!defined $kid) {
  ##  Some error happened
elsif ($kid == 0) {
  ##  Open/close filehandles, etc.
  ##  Run the command
  system ($cmd, @args);

  CORE::exit (0);

##  Parent process continues here...

It is possible I'm doing something wrong, but so far, this isn't working.  And if I replace
the $cmd with a Perl script and try to print out $ENV{LD_LIBRARY_PATH}, there is nothing.

Am I close?  I've googled a bit and I lost the page that I saw it (went to too many pages),
but one person put $cmd and the updated environment variable into a bash script and then ran
the bash script.  Any other thoughts?

Thank you!


View raw message