Note that there are some explanatory texts on larger screens.

plurals
  1. POperl fork doesn't work properly when run remotely (via ssh)
    primarykey
    data
    text
    <p>I have a perl script, script.pl which, when run, does a fork, the parent process outputs its pid to a file then exits while the child process outputs something to STOUT and then goes into a while loop.</p> <pre><code>$pid = fork(); if ( ! defined $pid ) { die "Failed to fork."; } #Parent process elsif($pid) { if(!open (PID, "&gt;&gt;running_PIDs")) { warn "Error opening file to append PID"; } print PID "$pid \n"; close PID; } #child process else { print "Output started"; while($loopControl) { #Do some stuff } } </code></pre> <p>This works fine when I call it locally ie: perl script.pl.</p> <p>The script prints out some things then returns control back to the shell. (while the child process goes off into its loop in the background).</p> <p>However, when I call this via ssh control is never returned back to the shell (nor is the "Output started" line ever printed.</p> <p>ie: $ ssh username@example.com 'perl script.pl'</p> <p>However, the interesting thing is, the child process does run (I can see it when I type ps). </p> <p>Can anyone explain whats going on?</p> <p>EDIT:</p> <p>I ran it under debug and got this:</p> ### Forked, but do not know how to create a new TTY. <p>Since two debuggers fight for the same TTY, input is severely entangled.</p> <p>I know how to switch the output to a different window in xterms and OS/2 consoles only. For a manual switch, put the name of the created TTY in $DB::fork_TTY, or define a function DB::get_fork_TTY() returning this.</p> <p>On UNIX-like systems one can get the name of a TTY for the given window by typing tty, and disconnect the shell from TTY by sleep 1000000.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload