http://www.perlmonks.org?node_id=507921

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.

Replies are listed 'Best First'.
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.