I have a perl script, script.pl that makes fork at startup, the parent process outputs the pid to a file, and then exits while the child process outputs something to STOUT, and then the loop goes into it for some time.
$pid = fork();
if ( ! defined $pid )
{
die "Failed to fork.";
}
elsif($pid)
{
if(!open (PID, ">>running_PIDs"))
{
warn "Error opening file to append PID";
}
print PID "$pid \n";
close PID;
}
else
{
print "Output started";
while($loopControl)
{
}
}
This works fine when I call it local, i.e.: perl script.pl.
The script prints some things and then returns control back to the shell. (while the child process goes into its loop in the background).
However, when I call it through an ssh control, it never returns back to the shell (nor does the "Start Record" line appear).
namely: $ ssh username@example.com 'perl script.pl'
However, the interesting thing is that the child process starts (I can see it when I type ps).
Can anyone explain what is happening?
EDIT:
I ran it under debugging and got the following:
### Forked, but don’t know how to create a new TTY.Since the two debuggers are fighting for the same TTY, the input is very confused.
I know how to switch output to another window in xterms and OS / 2. For a manual switch, enter the name of the created TTY in $ DB :: fork_TTY or define the function DB :: get_fork_TTY () that returns this.
On UNIX-like systems, you can get the TTY name for this window by typing tty and disconnecting the shell from TTY by sleeping 1,000,000.