Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Think about Loose Coupling
 
PerlMonks  

Script hangs or dies when run in background. Works fine in foreground.

by mears11 (Initiate)
on Nov 12, 2005 at 03:16 UTC ( #507921=perlquestion: print w/ replies, xml ) Need Help??
mears11 has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script that runs completely fine in the foreground, but will either hang or exit when run in background mode (tcsh shell in UNIX). The script calls three other scripts: Script 1: Syncs directory structures from two partitions Script 2: Syncs files within directories Script 3: Called in a loop and processes one or more files. All three made UNIX system calls via backticks. Originally, scripts 1 & 2 were called and had their output gathered via backtick and script 3 was called with open. I thought that it was the backticks that were causing the problems and I was receiving: suspended (tty output) messages, so I replaced the backtick calls to script 1 and 2 with open calls and it seemed to work. Then another user ran the wrapper script, backgrounded it, logged off, and the processes exited before completion (not sure if it was directly after logging off or not). What can I do to help these scripts run in the background? I have a feeling it has to do with reading input from the scripts with the open calls, but Iím not sure.

Considered: friedo: OP seems to have answered his own question. Delete?

Unconsidered: g0n: Keep votes prevent deletion Keep/Edit/Reap: 9/1/1

Comment on Script hangs or dies when run in background. Works fine in foreground.
Re: Script hangs or dies when run in background. Works fine in foreground.
by mears11 (Initiate) on Nov 12, 2005 at 03:17 UTC
    The problem was with stderr not being redirected to a file. I had a grep call that would sometimes write to stdout when a directory was empty. I also set: $SIG{HUP} = 'IGNORE'; Just to be on the safe side. Thanks.
Re: Script hangs or dies when run in background. Works fine in foreground.
by Rahushi (Initiate) on Apr 09, 2013 at 20:29 UTC
    Hi, How did you do that? I am facing same problem. My script runs fine in foreground but dies when I try to run in background. Any help would be highly appreciated.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-04-19 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls