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

Running a Background Job

by Anonymous Monk
on Nov 20, 2007 at 22:30 UTC ( [id://652008]=perlquestion: print w/replies, xml ) Need Help??

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

I have a script I would like to run as a background job on a Red Hat Linux box. When I run it without the "&", it runs fine. However, when I send it to the background (i.e. script.pl &), my top command does not execute. I tried everything to troubleshoot this issue but to no avail. What giveS? Thanks.
use strict; open (OUT,">top.log") or die "cannot create: $!\n"; for (;;){ my $top = `top n 1`; print $top; sleep 10; } close OUT;

Replies are listed 'Best First'.
Re: Running a Background Job
by andyford (Curate) on Nov 20, 2007 at 22:40 UTC
      Update: sorry, I thought you were saying 'perl' couldn't run in the background - didn't catch the issue with 'top' until after :-/

      What?! This is absolutely false. 'perl' can certainly run in the background!
      # perl -e 'print "hello\n"' > test.out 2>&1
      #cat test.out hello
Re: Running a Background Job
by ikegami (Patriarch) on Nov 20, 2007 at 22:51 UTC

    "my top command does not execute" is a rather vague problem description. Could you be more specific?

    If you're referring to the fact that nothing gets written to top.log, then you're mistaken when you said it runs fine without the "&". You never write anything to that file.

      Correction:
      use strict; open (OUT,">top.log") or die "cannot create: $!\n"; for (;;){ my $top = `top n 1`; print OUT $top; sleep 10; } close OUT;
      Sorry I was actually abbreviating my original script from memory. The script writes and executes top just fine when I don't run it as a background job. The explanation that top does not run as a background job is very helpful. Thank you.
Re: Running a Background Job
by hsinclai (Deacon) on Nov 20, 2007 at 23:44 UTC
      I managed to get top to work using the b argument. It's certainly not a Perl issue but it was quite baffling getting it to work properly. Thank you all for leading me in the right direction.
Re: Running a Background Job
by perlfan (Vicar) on Nov 21, 2007 at 00:02 UTC
    Does the following work?
    #perl script.pl > script.out 2>&1 &
    This doesn't sound like a Perl problem to me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found