The assignment of command output to an array hangs.

Discussion in 'Perl Misc' started by kaleem, Aug 11, 2006.

  1. kaleem

    kaleem Guest

    Hello,

    I've got a function in a package which I use to call system commands.
    Inside this function
    I've got the following code:

    @results = `$command`; # $command is the system command to run

    My problem is that this function (and the piece of code above) works
    fine but it fails for
    a particular command. It just hangs. The command which I'm calling is
    actually a KornShell
    script. I've verified that this script itself does not hang. I tried to
    use -d option to debug and I
    observed that the script hangs at the line shown above. Strangely, when
    I ran the same code
    using 'perl -e' it works! What I did was that I assigned the command to
    $command and then
    just put the same code as shown above. It worked with 'perl -e'.

    Please let me know how can I debug this problem further.

    Your responses will be greatly appreciated.

    Thanks.
    Kaleem.
     
    kaleem, Aug 11, 2006
    #1
    1. Advertising

  2. kaleem

    Paul Lalli Guest

    kaleem wrote:
    > Hello,
    >
    > I've got a function in a package which I use to call system commands.
    > Inside this function
    > I've got the following code:
    >
    > @results = `$command`; # $command is the system command to run
    >
    > My problem is that this function (and the piece of code above) works
    > fine but it fails for
    > a particular command. It just hangs. The command which I'm calling is
    > actually a KornShell
    > script. I've verified that this script itself does not hang. I tried to
    > use -d option to debug and I
    > observed that the script hangs at the line shown above. Strangely, when
    > I ran the same code
    > using 'perl -e' it works! What I did was that I assigned the command to
    > $command


    How? Are you confident $command contains what you think it does?

    > and then
    > just put the same code as shown above. It worked with 'perl -e'.


    You're asking us to trust that the code in your file is exactly the
    same as the code in your -e'' script. I don't. Please post a
    short-but-complete script that demonstrates your error.

    > Please let me know how can I debug this problem further.


    Step one would be printing out $command to verify that it is what you
    think it is. Did you think about newlines and chomping them? We have
    no idea what your actual code is like, so it's nigh impossible to help
    you debug it.

    Paul Lalli.
     
    Paul Lalli, Aug 11, 2006
    #2
    1. Advertising

  3. kaleem

    kaleem Guest

    Thanks for respoding Paul. Please note that I'm not a novice and I'm
    sure of what I'm
    saying. I mean I have checked all these things which you are asking me
    to check.
    Also, on further investigation I've found that after the KornShell
    script completes,
    it becomes defunct (zombie). It means that its parent hasn't waited for
    it. When
    I terminate the Perl script, this zombie process goes away.

    This is what my code looks like:

    cmd ("/abc/xyz/def 2>&1");

    /abc/xyz/def is a KornShell script.

    The cmd looks like this:

    sub cmd
    {
    $command = shift;

    .....

    @results = `$command`
    ....

    }

    Please note that the same code works if I just call /abc/xyz/def using
    cmd in
    another Perl script or using 'perl -e'. My actual script has lots of
    other code in addtition to calling /abc/xyz/def.

    Let me know what you think.

    Regards,
    Kaleem.

    Paul Lalli wrote:

    > kaleem wrote:
    > > Hello,
    > >
    > > I've got a function in a package which I use to call system commands.
    > > Inside this function
    > > I've got the following code:
    > >
    > > @results = `$command`; # $command is the system command to run
    > >
    > > My problem is that this function (and the piece of code above) works
    > > fine but it fails for
    > > a particular command. It just hangs. The command which I'm calling is
    > > actually a KornShell
    > > script. I've verified that this script itself does not hang. I tried to
    > > use -d option to debug and I
    > > observed that the script hangs at the line shown above. Strangely, when
    > > I ran the same code
    > > using 'perl -e' it works! What I did was that I assigned the command to
    > > $command

    >
    > How? Are you confident $command contains what you think it does?
    >
    > > and then
    > > just put the same code as shown above. It worked with 'perl -e'.

    >
    > You're asking us to trust that the code in your file is exactly the
    > same as the code in your -e'' script. I don't. Please post a
    > short-but-complete script that demonstrates your error.
    >
    > > Please let me know how can I debug this problem further.

    >
    > Step one would be printing out $command to verify that it is what you
    > think it is. Did you think about newlines and chomping them? We have
    > no idea what your actual code is like, so it's nigh impossible to help
    > you debug it.
    >
    > Paul Lalli.
     
    kaleem, Aug 11, 2006
    #3
  4. kaleem

    Paul Lalli Guest

    kaleem wrote:
    > Thanks for respoding Paul. Please note that I'm not a novice and I'm
    > sure of what I'm
    > saying. I mean I have checked all these things which you are asking me
    > to check.
    > Also, on further investigation I've found that after the KornShell
    > script completes,
    > it becomes defunct (zombie). It means that its parent hasn't waited for
    > it. When
    > I terminate the Perl script, this zombie process goes away.
    >
    > This is what my code looks like:
    >
    > cmd ("/abc/xyz/def 2>&1");
    >
    > /abc/xyz/def is a KornShell script.
    >
    > The cmd looks like this:
    >
    > sub cmd
    > {
    > $command = shift;
    >
    > ....
    >
    > @results = `$command`
    > ...
    >
    > }
    >
    > Please note that the same code works if I just call /abc/xyz/def using
    > cmd in
    > another Perl script or using 'perl -e'. My actual script has lots of
    > other code in addtition to calling /abc/xyz/def.
    >
    > Let me know what you think.


    I think you're very arrogant to assume that you have not made any
    mistakes, novice or expert. I asked you to post a short-but-complete
    script that we can run to test your problem, and you instead gave me
    pseudo code that simply restated what you said in your first post. You
    seem to be wanting us to come back and say "yup, there's a bug in Perl"
    rather than to actually help you diagnose what you may have done wrong.

    Do you want a solution to your problem, or do you want to avoid
    bruising your ego?

    Paul Lalli

    P.S. And to those who think this post was rude, yes it was. But in my
    opinion not undeservingly so.
     
    Paul Lalli, Aug 11, 2006
    #4
  5. kaleem

    kaleem Guest

    You are crude, Paul. Please don't ever reply to my any further
    postings. I never suggested
    that Perl had a bug or that I wanted you to come back and tell me that
    Perl had a bug. All I
    wanted to know was how to debug problem further. If I could provide
    code as it is I could
    have done it earlier.

    Thanks for being so nice.

    Paul Lalli wrote:

    > kaleem wrote:
    > > Thanks for respoding Paul. Please note that I'm not a novice and I'm
    > > sure of what I'm
    > > saying. I mean I have checked all these things which you are asking me
    > > to check.
    > > Also, on further investigation I've found that after the KornShell
    > > script completes,
    > > it becomes defunct (zombie). It means that its parent hasn't waited for
    > > it. When
    > > I terminate the Perl script, this zombie process goes away.
    > >
    > > This is what my code looks like:
    > >
    > > cmd ("/abc/xyz/def 2>&1");
    > >
    > > /abc/xyz/def is a KornShell script.
    > >
    > > The cmd looks like this:
    > >
    > > sub cmd
    > > {
    > > $command = shift;
    > >
    > > ....
    > >
    > > @results = `$command`
    > > ...
    > >
    > > }
    > >
    > > Please note that the same code works if I just call /abc/xyz/def using
    > > cmd in
    > > another Perl script or using 'perl -e'. My actual script has lots of
    > > other code in addtition to calling /abc/xyz/def.
    > >
    > > Let me know what you think.

    >
    > I think you're very arrogant to assume that you have not made any
    > mistakes, novice or expert. I asked you to post a short-but-complete
    > script that we can run to test your problem, and you instead gave me
    > pseudo code that simply restated what you said in your first post. You
    > seem to be wanting us to come back and say "yup, there's a bug in Perl"
    > rather than to actually help you diagnose what you may have done wrong.
    >
    > Do you want a solution to your problem, or do you want to avoid
    > bruising your ego?
    >
    > Paul Lalli
    >
    > P.S. And to those who think this post was rude, yes it was. But in my
    > opinion not undeservingly so.


    You are crude, Paul. Please don't ever reply to my any further
    postings. I never suggested
    that Perl had a bug or that I wanted you to come back and tell me that
    Perl had a bug. All I
    wanted to know was how to debug problem further. If I could provide
    code as it is I could
    have done it earlier.

    Thanks for being so nice.

    Paul Lalli wrote:
     
    kaleem, Aug 11, 2006
    #5
  6. kaleem

    Paul Lalli Guest

    kaleem wrote:
    > You are crude, Paul. Please don't ever reply to my any further postings.


    Sorry, you don't get to make that decision. If you don't want to see
    my posts, killfile me.

    > I never suggested
    > that Perl had a bug or that I wanted you to come back and tell me that
    > Perl had a bug. All I
    > wanted to know was how to debug problem further.


    And I told you exactly how to do that! You create a short-but-complete
    script that exhibits the problem. If your short-but-complete script
    doesn't exhibit the problem, then you figure out what you did
    differently between the short script and the "real" script.

    > If I could provide code as it is I could have done it earlier.


    You could have, but you didn't. Hence the problem. You want to know
    how to debug your program, but you don't want to actually put any
    effort into debugging your program.

    Paul Lalli
     
    Paul Lalli, Aug 11, 2006
    #6
  7. kaleem

    Mumia W. Guest

    On 08/11/2006 01:49 PM, kaleem wrote:
    > Thanks for respoding Paul. Please note that I'm not a novice and I'm
    > sure of what I'm
    > saying. I mean I have checked all these things which you are asking me
    > to check.
    > Also, on further investigation I've found that after the KornShell
    > script completes,
    > it becomes defunct (zombie). It means that its parent hasn't waited for
    > it. When
    > I terminate the Perl script, this zombie process goes away.
    >
    > This is what my code looks like:
    >
    > cmd ("/abc/xyz/def 2>&1");
    >
    > /abc/xyz/def is a KornShell script.
    >
    > The cmd looks like this:
    >
    > sub cmd
    > {
    > $command = shift;
    >
    > .....
    >
    > @results = `$command`
    > ....
    >
    > }
    >
    > Please note that the same code works if I just call /abc/xyz/def using
    > cmd in
    > another Perl script or using 'perl -e'. My actual script has lots of
    > other code in addtition to calling /abc/xyz/def.
    >
    > Let me know what you think.
    >
    > Regards,
    > Kaleem.
    >


    Please don't top-post.

    Your script is changing the environment such that your "def"
    script won't run correctly. Print out the environment
    variables for both successful and unsuccessful runs and
    compare them.
     
    Mumia W., Aug 11, 2006
    #7
  8. kaleem wrote:

    > I've found that after the KornShell script completes,
    > it becomes defunct (zombie). It means that its parent hasn't waited for
    > it.


    Right. IIRC readpipe() (aka qx aka `` ) will first wait for an EOF
    condition on the FIFO and then wait() for the exit status of the
    subprocess.

    The symptoms you describe indicate that most likely your subrocess has
    performed a fork-off-and-die without remebering to close (or redirect)
    STDOUT in the child.

    I can trivially reproduce the symptoms you are experiencing thus

    $ perl -e'`sleep 30 &`'

    The /bin/sleep process is still holding the FIFO open so the /bin/sh
    becomes a zombie for 30 seconds.
     
    Brian McCauley, Aug 13, 2006
    #8
  9. kaleem

    kaleem Guest

    Hey Brian,

    You seem to be the sensible (and technically adept) one here.:) The
    other two people who replied to my post seemed to be full of hubris and
    technically incompetent (trying to hide their incompetency asking me
    silly questions).

    Well, as I wrote, this problem is reproducible only in this particular
    case, I mean only in this particular Perl script of mine. In this
    script I have other code before this piece of code
    is executed where it hangs. If I created another Perl script which just
    has the problem code (the piece of code which hangs) it works fine! So
    it seems it might be a KornShell problem. Well, I'll try to look more
    into this and will get back. Thanks for respoding, man.

    Regards,
    Kaleem.


    Brian McCauley wrote:
    > kaleem wrote:
    >
    > > I've found that after the KornShell script completes,
    > > it becomes defunct (zombie). It means that its parent hasn't waited for
    > > it.

    >
    > Right. IIRC readpipe() (aka qx aka `` ) will first wait for an EOF
    > condition on the FIFO and then wait() for the exit status of the
    > subprocess.
    >
    > The symptoms you describe indicate that most likely your subrocess has
    > performed a fork-off-and-die without remebering to close (or redirect)
    > STDOUT in the child.
    >
    > I can trivially reproduce the symptoms you are experiencing thus
    >
    > $ perl -e'`sleep 30 &`'
    >
    > The /bin/sleep process is still holding the FIFO open so the /bin/sh
    > becomes a zombie for 30 seconds.
     
    kaleem, Aug 14, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul A. Rubin

    Re: Cplex hangs in Perl system command

    Paul A. Rubin, Aug 4, 2003, in forum: Perl
    Replies:
    2
    Views:
    3,630
    Paul A. Rubin
    Aug 5, 2003
  2. nagy
    Replies:
    36
    Views:
    1,062
    Terry Reedy
    Jul 20, 2006
  3. Chris
    Replies:
    34
    Views:
    1,598
  4. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    422
    Ville Mattila
    Jul 24, 2005
  5. Jarrod Menoube

    gem command hangs with no output

    Jarrod Menoube, Aug 29, 2008, in forum: Ruby
    Replies:
    3
    Views:
    111
    deepak
    Sep 2, 2008
Loading...

Share This Page