Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Forking child process gives me an error: Attempt to free unreferenced scalar

by srlbharu (Acolyte)
on Feb 26, 2013 at 11:45 UTC ( [id://1020671]=perlquestion: print w/replies, xml ) Need Help??

srlbharu has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I was wondering if someone could lend me a solution. I have a list of commands in a text file, that my script reads in one at a time, and then I try to execute one by one. Each command will be executed as eval $cmd; and the $cmd will the subroutine in which we will send the actual command through socket. Once the command sent, we wait for the response at max period of 90sec. Here is the requirement: I need to send couple of commands from the list for which I should not wait for the response and move to further commands. To achieve this, I planned to create child process as background for that particular command. Since our project drives with perl5.6, I had no choice to use threads to do so. Hence I created using fork.This leads to perl interpreter crach by throwing an error: Attempt to free unreferenced scalar. Here is the code that I tried to create child:

foreach (@commands) { $cmd = $_; if($cmd =~ /CGDCONT/i){ unless (fork) { eval $cmd; if ($@) { print "When executing: $cmd\nFollowing error occured: + $@\n"; } exit; } } else{ eval $cmd; if ($@) { print "When executing: $cmd\nFollowing error occured: $@\n +"; } } }
FYI.. $cmd will be holding subroutine API call from one of my user defined perl modules with different arguments. If it is required debug the issue, I can share the source code of $cmd API also.

  • Comment on Forking child process gives me an error: Attempt to free unreferenced scalar
  • Download Code

Replies are listed 'Best First'.
Re: Forking child process gives me an error: Attempt to free unreferenced scalar
by tmharish (Friar) on Feb 26, 2013 at 11:49 UTC

    See this related thread that asks for almost(?) the same thing.

      No response from him :-(
Re: Forking child process gives me an error: Attempt to free unreferenced scalar
by Corion (Patriarch) on Feb 27, 2013 at 07:51 UTC

    If you are on Windows, you shouldn't use <c>fork()/<c>. 5.6.1 has threads, so maybe you can use threads.

    I recommend launching an external program/script to do the processing for each command in parallel.

      Can you please let me know how to create a thread to run parallelly? I tried but failed. After google, I came to know threads have been depricated in 5.6.1.

        See threads.

        If you have specific problems, please post code.

Re: Forking child process gives me an error: Attempt to free unreferenced scalar
by Anonymous Monk on Jul 25, 2013 at 08:49 UTC

    I had exactly this issue, but only when running under windows. I found if I swapped out the foreach construct for a while and shift mechanism for looping the @commands array it worked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1020671]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found