LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ssh -> perl -> spawn background proces hangs ssh session (https://www.linuxquestions.org/questions/programming-9/ssh-perl-spawn-background-proces-hangs-ssh-session-438349/)

rhoekstra 04-24-2006 10:06 AM

ssh -> perl -> spawn background proces hangs ssh session
 
Hi,

I have a back-up policy that logs into machines to run a perl script. This script runs processes like database listeners or apachectl processes.

These processes do daemonize, but they get stuck attached to the logon terminal, making ssh to hang on exit. You'll have to break the process to regain control of the tty (or interactively, use '\n~.' to terminate the ssh session).

On bash scripting, the solution mostly is redirection of input / output, like: 'apachectl </dev/null &>/dev/null'.

In perl, however, this doesn't seem to work..

Any of you who has experienced this before and know of a solution to this?? I can't seem to be able to find a proper solution to this.

Thanks..

Belenos 04-24-2006 03:37 PM

Fragment of script that launches a "sticky" process:

#!/usr/bin/perl
<set up $script_file>
my $pid = fork;

if ($pid) {

my $pid_return = waitpid($pid,0);
my $fork_return = $? >> 8;
my $message = ($fork_return) ? "FAILED" : "SUCCESS";
print "Requested Fork ", $message, "\n";
exit $fork_return;
}

die "Could Not Fork: $!" unless defined($pid);
close STDIN;
close STDOUT;
close STDERR;

POSIX::setsid() or die "Could Not Start New Session: $!";

my $sys_return = system($script_file);
my $retcode = $sys_return >> 8;
exit $retcode;

rhoekstra 04-25-2006 01:05 AM

Thanks in advance! I will try this right away... :)
If it works... you've just made my day lol..


All times are GMT -5. The time now is 01:21 AM.