Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

script hangs after executing program

by jeanluca (Deacon)
on Dec 15, 2006 at 16:54 UTC ( [id://590058]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks

I'm writing a big (complex) program (which I shouldn't have done in the first place) but now I have to continue and finish it.

Anyway, when I try to execute a program from within my script, for example like
system("$prog -f $fname ") ;

It executes it but for some reason it never seems to leave this call. First I blamed the program I was calling, but after running it, without any problems, using a small test script and also the command line, it became crystal clear and I realized it had to do with me, myself and my script :(

It only seems to happen with this program, because I can call ls without problems.....
So, all this stuff is new for me, which means I don't know what information can be relevant to post here!

If there is a monk outside that has a clue, I would really like to hear it!!!

Thanks a lot
LuCa

ps I also tried to call the program with open and with `....`, but with the same result

Replies are listed 'Best First'.
Re: script hangs after executing program
by monkey_boy (Priest) on Dec 15, 2006 at 17:07 UTC
    Are you sure its this line thats causing the hang? 1st try this:
    $|=1; print "got here!\n" system("$prog -f $fname ") ; print "And i also got here!\n";

    My second guess is that the $prog is waiting for something, like some data to be piped to it, what does the "top" command show, is it using cpu etc?
    I guess we would need a lot more info on $prog to make a better guess.


    This is not a Signature...
Re: script hangs after executing program
by McMagnus (Novice) on Dec 16, 2006 at 04:37 UTC
    As an alternative to adding debug print statements around your system statement, you can use ps -fu <user running script> from another terminal to determine if $prog is still an active process when you think it is hung.

    If it is still running, you may be able to get some idea what it is doing by running strace -p <pid of $prog>.
    If this generates a continuous stream of output, $prog may be looping trying to access some resource.
    If it only generates a few lines of output it may be waiting for some user input.

    Both of these suggestions are specific to Linux/UNIX. I am not sure if there are Windows equivalents.

Re: script hangs after executing program
by moklevat (Priest) on Dec 15, 2006 at 17:10 UTC
    I'm not certain I can help with the specific problem without knowing more about $prog. However, I wonder if when you say you tried open, you meant to say exec instead, because open and system are not similar system and exec are similar.

    Updated: monkey_boy points out below how system and open can indeed be similar, but without knowing what $prog is doing I don't know that it can be assumed to be so in this case. However, I updated the text above to say what I mean more clearly.

    My apologies to open, I meant no disrespect.

      open and system can be very similar.. what happens when you do this:
      open ( my $fh , "ps -elf |"); print $_ while(<$fh>);



      This is not a Signature...
Re: script hangs after executing program
by sgt (Deacon) on Dec 15, 2006 at 21:24 UTC

    something waiting for input? even ls can hang if it cannot determine the terminal size (but ls -1 does not), quite a few commands can suffer from this actually (top is another good example)

    if you vary $prog what does happen? e.g try '/bin/ksh -c echo aa' with appropriate redirects

    hth --stephan
Re: script hangs after executing program
by jeanluca (Deacon) on Dec 15, 2006 at 18:21 UTC
    thanx for the answers. Right now I'm not behind the computer with my software, so we have to take it over the weekend.

    Monday I'll try the suggestions and I will come with some additional information!

    LuCa
Re: script hangs after executing program
by jeanluca (Deacon) on Dec 18, 2006 at 13:01 UTC
    Brethern,

    working on all the suggestions I noticed that after about a minute or so, my script continued, meaning that $prog finished! That was of course good news, but still I needed to figure out why it didn't do the job in a fraction of a second!
    When I started strace -p <pid of $prog>(suggested by McMagnus) I saw what the problem was, $prog was writing data to files at a very slow speed.

    Changing the working directory of my program to a different disk solved the problem!!

    I have 3 internal IDE disks, so I did a performance test on this disk, like
    time dd if=/dev/zero bs=1024k count=2048 of=bigfile
    and the result was acceptable 15MB/sec ( $prog creates a couple of files with a total size of +/-30KB)

    So, although I have still a couple of whys, I consider the problem as solved!!

    Thanx a lot!
    LuCa
Re: script hangs after executing program
by rblasch (Monk) on Dec 17, 2006 at 17:04 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-28 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found